using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text.RegularExpressions; using System.Linq; namespace codeTest { class Program { static void Main(string[] args) { MyClass myClass1 = new MyClass() { FristName = "myClass1", LastName = "LmyClass1" }; MyClass myClass2 = new MyClass("myClass2", "LmyClass2"); MyClass myClass3 = new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 }; myClass1.Show(); myClass2.Show(); myClass3.Show(); List<MyClass> list = new List<MyClass>() { new MyClass() { FristName = "myClass1", LastName = "LmyClass1" }, new MyClass("myClass2", "LmyClass2"), new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 } }; Dictionary<int, MyClass> dic = new Dictionary<int, MyClass>() { {1,new MyClass() { FristName = "myClass1", LastName = "LmyClass1" }} , {2,new MyClass("myClass2", "LmyClass2")} , {3,new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id=3 }} }; Console.ReadLine(); } } public class MyClass { public string FristName; public string LastName { get; set; } public int id { get; set; } public MyClass() { } public MyClass(string frist,string last) { FristName = frist; LastName = last; } public void Show() { Console.WriteLine("FristName:{0} LastName:{1} id:{2}", FristName, LastName, id); } } }
时间: 2024-10-13 13:17:33