C#3.0之自动属性和对象初始化器举例
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CAPP
{
class Program
{
static void Main(string[] args)
{
Person p1 = new Person
{
Name = "张四",
Age = 23,
Sex = "女",
Address = new Address { City = "成都市", Street = "高新区" }
};
p1.Sayhi();
Console.ReadKey();
}
}
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Sex { get; set; }
public Address Address { get; set; }
public void Sayhi()
{
Console.Write("大家好,我是{0},今年{1},是个{2}生,家住{3}{4}", Name, Age, Sex, Address.City, Address.Street);
}
}
class Address
{
public string City { get; set; }
public string Street { get; set; }
}
}
摘自 zjk20108023的专栏
补充:软件开发 , C# ,