c#学习第五天 枚举和结构体

//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]);

}



}

}



}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值