zoukankan      html  css  js  c++  java
  • c#小知识点

    整理一些比较实用的代码;

    1.Thread.Sleep(100);  //休眠 单位 毫秒
    2.Console.Clear();     // 清屏

    3.foreach (int z in num)   //从索引0位置遍历数组至结束为止
    {
    Console.WriteLine(z);
    }

    等价于:

    for (int i = 0; i < num.Length; i++)
    {
    Console.WriteLine(num[i]);

    }

    4.描述按下的控制台键

    ConsoleKeyInfo key = Console.ReadKey();
    string s = key.KeyChar.ToString();

    Key :获取当前 ConsoleKeyInfo 对象表示的控制台键

    KeyChar:获取当前 ConsoleKeyInfo 对象表示的 Unicode 字符。

     5.字符串操作

    l.length 字符串长度,字符串个数
    Console.WriteLine(s.Length );
    Console.WriteLine(s.TrimStart()); //去掉前面的空格
    s.TrimEnd();//去掉后边的空格
    Console.WriteLine(s.ToLower ());//转换成小写
    Console.WriteLine(s.ToUpper());//转换成大写
    bool isbaohan = s.Contains("if");//判断字符串中是否包含某字符段
    Console.WriteLine(isbaohan);
    //字符串有长度,有索引 索引从0开始到length-1结束

    int index = s.IndexOf("if",4);
    Console.WriteLine(index);
    int lastid = s.LastIndexOf("as");
    Console.WriteLine(lastid );


    string jqs = s.Substring(4,3);//(截取的索引位置,截取个数)
    Console.WriteLine(jqs);

  • 相关阅读:
    Hive小结
    Redis小结
    Hbase小结
    Rdd/DataFrame/DataSet 小结
    spark杂记2
    shiyan
    stanford推荐阅读目录
    超市收银系统之——3
    超市收银系统之超市类——4
    超市收银系统_仓库类——2
  • 原文地址:https://www.cnblogs.com/miss123/p/5343732.html
Copyright © 2011-2022 走看看