- class Program
- {
- static void Main(string[] args)
- {
- Person p1 = new Person();[b][/b]
- p1.Name = "张三";
- p1.Age = 18;
- p1.Sex='男';
- p1.SayHello();
- Console.ReadKey();
- }
- }
- class Person
- {
- string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- int age;
- public int Age
- {
- get { return age; }
- set { age = value; }
- }
- char sex;
- public char Sex
- {
- get { return sex; }
- set { sex = value; }
- }
- public void SayHello()
- {
- Console.WriteLine("大家好,我叫{0},我今年{1}岁了,我是{2}生", name, age, sex);
- }
- }
复制代码 |