c# 学习记录1

 

1. c# 结构:多种类型变量的集合

【语法:】
[public] struct 结构名称
{
  public int/string/char/... 变量名称1;
  public int/string/char/... 变量名称2;
  public int/string/char/... 变量名称3;
}

//例:
public struct Person
{
  public string name;
  public int age;
  public char sex;
}

Person xiaoming;
xiaoming.name="小明";
xiaoming.age=18;
xiaoming.sex='男';

//2. 枚举:多种常量的集合

//【语法:】
public enum 枚举名称
{
  常量1,
  常量2,
  常量3,
  ...  
}
//例:
public enum Color
{
  Red,
  Green,
  Blue,
  Yello,
  Black
}

//【调用办法】
//Color.Red // Color.Green // Color.Blue // ......


//3. 数组:同种类型变量的集合

//【语法:】
1) int[] 数组名称 = new int[x];     //其中 x 代表的是数组的长度;
2) int[] 数组名称 = {x,x,x,x,x,....} //其中 x 代表的是数组的成员。

//例如:
1) int[] Nums = new int[3];
  Nums[0]=110;
  Nums[1]=120;
  Nums[2]=119;
2) string[] Str_name = {"zhangsan","lisi","wangwu"};

 

 

  

posted @ 2021-01-12 21:18  Googleblog  阅读(45)  评论(0)    收藏  举报