//enum在c#中可以再创建一个.cs文件,也可以在默认的cs文件里面创建(program.cs)
//enum和类是同等级关系
enum Color{
red,
green,
yellow,
blue
}
class Program{
static void Main(string[] args){
Color c = (Color)0; //如果数字是负数,就需要加上括号
switch(c){
case 0:
Console.WriteLine("红色");
break;
case (Color)1:
Console.WriteLine("绿色");
break;
case (Color)2:
Console.WriteLine("黄色");
break;
case (Color)3:
Console.WriteLine("蓝色");
Console.WriteLine((int)Color.green);
break;
}
}
//将int-->enum
//强制转换 enum e = (enum)1;
//将enum-->int
//强制转换 int a =(int) Color.blue;
//enum-->string
//string s = Enum.GetName(typeof(Color),3);
//Console.WriteLine(s);
//string-->enum
//Color c = (Color)Enum.Parse(typeof(Color),"red");
//Console.WriteLine(c);
//Enum.TryParse<>;
//补充---与运算以及或运算
//与运算,对位全是1,结果就是1,否则0
//Color c = Color.red & Color.blue;
//Console.WriteLine(c);
或运算,对应全是0,结果就是0,否则1
//Color c1 = Color.red | Color.blue | Color.green;
//Console.WriteLine(c1);
struct Student{
//包含姓名,年龄,学号,分数
public string name;
public int age;
public int stuId;
public int score;
public Student(string name,int age,int stuId,int score){
this.name =name;
this.age =age;
this.stuId = stuId;
this.score = score;
}
class Program{
static void Main(string[] args){
Student sd = new Student("周杰伦",23,1000,90);
Student sd1 = new Student("王力宏",25,1001,100);
Student sd2 = new Student("周杰",30,1002,50);
Student sd3 = new Student("王杰",35,1003,60);
Student sd4 = new Student("容嬷嬷",50,1004,20);
int[] arr = {sd.score, sd1.score, sd2.score, sd3.score ,sd4.score};
for(int i=1;i<=5;i++){
for(int j =1;j<=5;i++){
if(arr[i-1]>arr[i]){
int temp = arr[i];
arr[i] = arr[i-1];
arr[i-1]=temp;
}
}
}
for(int i= 0;i<arr.Length;i++){
Console.WriteLine(arr[i]);
}
}
}
}