类的复习——7月25日

类的复习

// //String类
           // string s = "   Hello   ";
           // //长度
           // int a = s.Length;

           // //去掉前后空格
           // Console.Write(s.Trim());
           // //去掉前面的空格
           // Console.WriteLine(s.TrimStart());
           // //去掉后面的空格
           // Console.WriteLine(s.TrimEnd());

           // //将所有小写转换为大写
           // Console.WriteLine(s.ToUpper());
           // //将所有大写转换为小写
           // Console.WriteLine(s.ToLower());

           // //第一次出现的索引
           // Console.WriteLine(s.IndexOf("h"));
           // //最后一次出现的索引
           // Console.WriteLine(s.LastIndexOf("t"));
           // //索引号是从0开始的
           // //长度要比最后一位的索引号大1

           // //截取,从某个位置到最后
           // Console.WriteLine(s.Substring(3));
           // //从某个位置开始截取多长
           // Console.WriteLine(s.Substring(3,5));

           // //判断是否包含
           // Console.WriteLine(s.Contains("A"));
           // //判断是否以***开头
           // Console.WriteLine(s.StartsWith(" "));
           // //判断是否以***结尾
           // Console.WriteLine(s.EndsWith("x"));

           // //替换
           // Console.WriteLine(s.Replace("l","L"));


           // //Math类   数学类
           // double b = 3.14;
           // //取上线
           // Console.WriteLine(Math.Ceiling(b));
           // //取下线
           // Console.WriteLine(Math.Floor(b));
           // //取四舍五入
           // Console.WriteLine(Math.Round(b));
           // //π
           // Console.WriteLine(Math.PI);
           // //开平方根
           // Console.WriteLine(Math.Sqrt(b));



           // //DateTime类     日期时间类
           ////初始化
           // //DateTime dt = new DateTime();
           // //获取当前时间
           // //DateTime dt = DateTime.Now;
           // //接收一个输入的时间日期
           // DateTime dt = DateTime.Parse(Console.ReadLine());
           // Console.WriteLine(dt.Month);
           // dt.AddDays(-10);
           // //时间段(时间间隔)
           // TimeSpan ts = new TimeSpan(3,3,3,3);
           // dt.Add(ts);



           // //随机数类Random
           // //初始化
           // Random ran = new Random();
           // int sui = ran.Next(20,31);


           // Console.ReadLine();

练习:四位验证码

            //练习:随机出现一个四位数的验证码,打印出来
            //比照打出来,验证输入的验证码是否正确
            //验证码不区分大小写
            string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random ran = new Random();
            string s1 = s.Substring(ran.Next(0, 62), 1);//表示从ran.Next(0, 62)这个索引号开始截取,截取一个长度。
            string s2 = s.Substring(ran.Next(0, 62), 1);//ran.Next(0, 62)表示从0~62范围内的随机数,取到下线61。
            string s3 = s.Substring(ran.Next(0, 62), 1);
            string s4 = s.Substring(ran.Next(0, 62), 1);
            string s5 = s1 + s2 + s3 + s4;
            Console.WriteLine("验证码:" + s5);
            Console.Write("请输入验证码:");
            string y = Console.ReadLine();
            string m1 = s5.ToUpper();
            string m2 = y.ToUpper();
            if (m1 == m2)
            {
                Console.WriteLine("您输入的验证码正确!");
            }
            else
            {
                Console.WriteLine("您输入的验证码有误!");
            }
            Console.ReadLine();
原文地址:https://www.cnblogs.com/juyangchao12/p/5712730.html