1.属性的定义及使用
class MyClass { private int id = 1; //属性的定义 private string name = ""; //属性的定义 public int Id { get { return id; } set { id = value; } } public string Name { get { return name; } set { name = value; } } }
static void Main(string[] args) { //实例化一个对象myclass MyClass myclass = new MyClass(); //给对象赋值 myclass.Id = 77; myclass.Name = "AAAAA"; //输出 Console.WriteLine(myclass.Id +" "+ myclass.Name); //实例化一个对象myclass2 MyClass myclass2 = new MyClass(); //给对象赋值 myclass2.Id = 88; myclass2.Name = "BBBBB"; Console.WriteLine(myclass2.Id + " " + myclass2.Name); Console.ReadLine(); }