簡易範例
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
demo d = new demo();
Console.WriteLine("--------------------------");
demo d1 = new demo("this 測試,呼叫預設建構子");
Console.WriteLine("--------------------------");
demo d2 = new demo("this 測試" , "呼叫指定建構子");
}
}
public class demo
{
public demo()
{
Console.WriteLine("預設建構子");
}
public demo(string data) : this()
{
Console.WriteLine($"建構子1:{data}");
}
public demo(string data1 , string data2) : this(data2)
{
Console.WriteLine($"建構子2:{data1}-{data2}");
}
}
}
沒有留言:
張貼留言