c#交换数,判断通过考试

 static void Swap( ref int x, ref int y)
         {
    
    
             int temp;
             temp = x;
             x = y;
             y = temp;
        }
            int m = 2, n = 3;
            Console.WriteLine("交换前,两个数{0}和{1}",m,n);
            Swap(ref m,ref n);
            Console.WriteLine("交换后,两个数{0}和{1}", m,n);
            Console.ReadKey();

在这里插入图片描述

class Student
    {
    
    
       public  string name;
         int Score;
         public int Score1
        {
    
    
            get {
    
     return Score; }
            set {
    
    
                Score = value;
                if (value >= 0 && value <= 100)
                {
    
    
                    Score = value;
                }
                else
                    Score = -1;
            }
        }
    }

            Student stu = new Student();
            Console.WriteLine("请输入你的姓名");
            stu.name = Console.ReadLine();
            Console.WriteLine("请输入你的成绩");
            stu.Score1 = int.Parse(Console.ReadLine());
            if (stu.Score1 == -1)
            {
    
    
                Console.WriteLine("数据非法");
            }
            else
            {
    
    
                if (stu.Score1 >= 60 && stu.Score1 <= 100)
                {
    
    
                    Console.WriteLine("您通过了考试");
                }
                else if (stu.Score1 <= 60)
                {
    
    
                    Console.WriteLine("未通过了考试");
                }
            }
            Console.ReadKey();

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41920585/article/details/110697076