类:
class Lei //要和static void Main(string[] args)平级;
{
public int lei_int; //public是关键字,代表访问权限,这里是公共的;(private:仅自己可见;protect:对同一个包内,以及子程序可见)
public string lei_string;
} //定义类,class类型
List<Lei> lei1 = new List<Lei>(); //泛型集合定义类型;
Lei sx = new Lei(); //新建sx对象
sx.lei_int = 1; //赋值
sx.lei_string = "孙晓"; //赋值
lei1.Add(sx); //插入
Lei xsx = new Lei();
x1.lei_int = 2;
x1.lei_string = "小孙晓";
lei1.Add(xsx);
foreach (Lei x in lei1)
{
Console.WriteLine(x.lei_int);
Console.WriteLine(x.lei_string);
} //遍历
Console.Read();
结构体:
truct Jie //要和static void Main(string[] args)平级;
{
public int jie_id;
public string jie_name;
}
Jie> jie1 = new List<Jie>(); //
Jie sx = new Jie();
sx.jie_id = 1993;
sx.jie_name = "sunxiao";
jie1.Add(sx);
foreach (var x in jie1)
{
Console.WriteLine(x.jie_id);
Console.WriteLine(x.jie_name);
}
枚举:
enum Asd
{
哈啊,
哈哈,
呵呵
}
Console.WriteLine(Asd.哈哈);
//定义了什么,就只能输出什么