注意:枚举类型和结构体都属于值类型。 结构体:就是一个自定义的集合,里面可以放各种类型的元素,用法大体跟集合一样。一、定义的方法:struct student{public int nianling;public int fenshu;public string name;p ...
注意:枚举类型和结构体都属于值类型。
结构体:就是一个自定义的集合,里面可以放各种类型的元素,用法大体跟集合一样。
一、定义的方法:
struct student
{
public int nianling;
public int fenshu;
public get='_blank'>string name;
public string sex;
public int sum;
}
以上的语句就是定义一个名称为student的结构体,其中包含int类型的年龄、分数、总和,和string类型的姓名、性别。
二、用法:
在main主函数外面定义了一个名称为student的结构体,以便于main函数之中使用。
student st = new student();//这句话是在main函数之中定义了一个名为st的student类型的结构体。
下面开始为里面的每个元素赋值:(结构体名+点+结构体里面的变量名称=值)
main函数下
{
st.nianling=22;
st.fenshu=80;
st.name="小李";
}
赋值完成之后可以打印出被赋值的项。
三、结构体类型里面包含结构体类型:
可以在此前的student的结构体中在定义一个结构体
public shuxing sx;//代表一个shuxing结构体变量组
原标题:C#枚举类型和结构体
关键词:C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。