コンストラクション関数:this
3144 ワード
Test.cs:
Program.cs
class Test
{
public string Name { get; set; }
public string Address { get; set; }
public Test()
: this(null, null)
{
}
public Test(string name)
: this(name, null)
{
}
public Test(string name, string address)
{
this.Name = name;
this.Address = address;
}
}
Program.cs
static void Main(string[] args)
{
Test test1 = new Test();
Test test2 = new Test(" 1");
Test test3 = new Test(" 2", " ");
Console.WriteLine("Name:" + test1.Name + "...Address:" + test1.Address);
Console.WriteLine("Name:" + test2.Name + "...Address:" + test2.Address);
Console.WriteLine("Name:" + test3.Name + "...Address:" + test3.Address);
}