C#学习笔记12:枚举、结构、数组基础学习

枚举:public enum MyEnum

{

值1,

值2,

值3

}

Public enum Season

{

春,

夏,

秋,

}

枚举的作用:规范用户的输入,枚举可以转换为int类型,可以转换为字符串类型吧。默认从0开始。

枚举转换为int类型:Int a=(int)Season.春

枚举转换成字符串:

String a=Season.春.ToString();

结构:可以一次性声明多个不同类型的变量。

Public strcuct MyStruct

{

字段1;

字段2;

字段3;

}

字段跟变量的区别:

字段有访问修饰符。 变量又作用域

当咱们需要一个变量在整个类中都能够被访问到,声明成一个静态的字段。

Public static string _name="张三";//声明在类里,方法外

程序在运行期间,变量中只能有一个值,而字段中可以有多个值。

数组

Int[] string[] char[]

声明数组的几种方式

Int[] nums=new int[10]; 0

Int[] nums=new int[3]{1,2,3};

String[] names=new string[]{"shan"};

Char[] ch=new char[2]{'a','b'};

String[] str=new string[10]; null

Char[] chs=new char[10]; ‘\0’

Int double char bool decimal 结构 枚举 都是值类型

String 数组 接口 类 object 都是引用类型

(除非注明,文章均为原创,欢迎转载,转载时请注明出处链接:智波生活 C#菜鸟笔记