zoukankan      html  css  js  c++  java
  • 类型

    //必须通过new初始化变量,后面括号是构造函数
    
                int cuo = 0;
                Console.WriteLine("请输入时间");
                string s = Console.ReadLine();
                //datetime实际是一个类。
                try
                {
                    DateTime dt = DateTime.Parse(s);
    
                }
                catch (Exception ex)
                {
                    Console.WriteLine("不是");
                    cuo = 1;
    
                }
    
                if (cuo == 0)
                {
                    Console.WriteLine("正确   ");
                }
                //类 类型 class 类型;用户自定义类型
                //String :处理字符串
                //Datetime:处理时间     
                //Ramdom: 生成随机数
                //Math:处理数字
    
                string s = "      adasdasda";
    
                int changdu = s.Length;//返回字符串的长度
                Console.WriteLine(changdu);
                s.Trim(); //去除空格。
                s.TrimEnd();//去后空格
                s.TrimStart();//去前空格
                s.ToLower();//转化为小写
                s.ToUpper();//抓化为大写
                
                //截取字符串;字符串是有索引的,索引从0开始
    
    
                string js = "abcdefghabcdefgabcdefgabcdefgefi";
                string jqh = js.Substring(2);
                Console.WriteLine(jqh);
    
                int id = js.IndexOf("ef",5);//差第一个匹配项的索引
                  Console.WriteLine(id);
    
                  int idd = js.LastIndexOf("ef");
                  Console.WriteLine(idd);
    
                  string news = js.Replace("ef", "123");
    
                  Console.WriteLine(js);
                  Console.WriteLine(news);
    
                string s = "a|b|c|d|ab|cd|";
                    string[] str = s.Split('|');
                foreach (string d in str)
                {
                    Console.WriteLine(d);
                }
                //Math类:里边有些处理数字的方法,静态方法
              int i=  Math.Abs(-5);//取绝对值
                Console.WriteLine(i);
                double a = Math.Ceiling(1.1);//上限取整数
                
                Console.WriteLine(a);
               double b= Math.Floor(1.9);//取下线整数值
    
                Console.WriteLine(b);
                Console.WriteLine(Math.Round(1.52));//四舍五入
                Console.WriteLine(Math.PI);//圆周率
                Console.WriteLine(Math.Pow(2, 3));//指定数字的几次方
                Console.WriteLine(Math.Sqrt(16));//求平方根
                Console.ReadLine();
    
                //随机数
                Random r = new Random();
    
                for (int i = 0; i <= 100; i++)
                {
                    int shu = r.Next(1001, 9999);
                    Console.WriteLine(shu);
                    Thread.Sleep(100);
                    Console.Clear();
                }
    
                Console.WriteLine("中奖人是曹凯" );
                DateTime dt = new DateTime(2015,11,20,15,32,50);
               int year= dt.Year;
               int mouth= dt.Month;
                Console.WriteLine(year);
                Console.WriteLine(mouth);
    
                DateTime dt2 =  DateTime.Now;//获取系统当前时间。
                Console.WriteLine(dt2.ToString());
                int sumday = dt2.DayOfYear;//获取改年中的第几天
                Console.WriteLine(sumday);
    
                DateTime dt3 = dt2.AddYears(3);
                Console.WriteLine(dt3.ToString("yyyy年MM月dd日"));
    
    
                //字符串型转DateTime型
    
                string st = "2015/9/14";
                Console.WriteLine(st.ToString());
    
                Console.ReadLine();
    

      

  • 相关阅读:
    JVM — 类加载机制
    java 异常处理
    (前篇:NIO系列 推荐阅读) Java NIO 底层原理
    (六:NIO系列) 相关设计模式
    (五:NIO系列) Reactor模式
    (四:NIO系列) Java NIO Selector
    (三:NIO系列) Java NIO Channel
    (二:NIO系列) Java NIO Buffer
    (一:NIO系列)JAVA NIO 简介
    java 线程池(线程的复用)
  • 原文地址:https://www.cnblogs.com/suncan0/p/4987563.html
Copyright © 2011-2022 走看看