C#的初始化器

时间:2021-10-08 15:47:44
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= };
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= }
};
Dictionary<int, MyClass> dic = new Dictionary<int, MyClass>()
{
{,new MyClass() { FristName = "myClass1", LastName = "LmyClass1" }} ,
{,new MyClass("myClass2", "LmyClass2")} ,
{,new MyClass("myClass2", "LmyClass2") { FristName = "myClass3", LastName = "LmyClass3",id= }}
};
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);
}
} }