zoukankan      html  css  js  c++  java
  • C#基础知识记录一

    C#基础知识记录一

    static void Main(string[] args)
    
            {
    
                #region 合并运算符的使用(合并运算符??) 更多运算符请参考:https://msdn.microsoft.com/zh-cn/library/ms173224(v=vs.100).aspx
    
                int? x = null;
    
     
    
                //合并运算符的写法
    
                int? y = x ?? 0;
    
                //三元运算符的写法:
    
                y = x == null ? 0 : x;
    
                Console.WriteLine(y);
    
     
    
                #endregion
    
     
    
                #region 多维数组 参考MSDN:https://msdn.microsoft.com/zh-cn/library/2yd9wwz4(v=vs.80).aspx
    
                //二维数组(3行3列)
    
                int[,] array2 = new int[3, 3];
    
                int[,] arr2 = { { 1, 2 }, { 2, 3 }, { 4, 5 } };
    
                int[, ,] arr3 = { { { 1, 2, 3 } }, { { 2, 3, 4 } }, { { 4, 5, 6 } } };
    
                foreach (var item in arr3)
    
                {
    
                    Console.Write(item);
    
                }
    
                //三维数组:
    
                int[, ,] array3 = new int[3, 3, 3];
    
                //锯齿数组(更灵活的方式):
    
                int[][] juarray = new int[3][];
    
                juarray[0] = new int[2] { 1, 2 };
    
                //嵌套循环锯齿数组:
    
                for (int i = 0; i < juarray.Length; i++)
    
                {
    
                    if (juarray[i] != null)
    
                        for (int j = 0; j < juarray[i].Length; j++)
    
                        {
    
                            Console.WriteLine("值为:{0}", juarray[i][j]);
    
                        }
    
                }
    
                Console.WriteLine(juarray[0][0]);
    
     
    
                #endregion
    
     
    
                #region 字符串正则表达式
    
                //------基础----------------
    
                /* 元字符:  .:表示匹配除换行以外的任意字符  :匹配单词开始或者结束  d:匹配数字  s:匹配任意的空白字符
    
                 *  ^ :匹配字符串的开始   $ :匹配字符串的结束
    
                 *  限定符:  *:重复0次或者多次  +:重复一次或者多次  ? :重复0次或者1次  {n}:重复n次   {n,} :重复n次或者更多次
    
                 *    {n,m} :重复n到m次
    
                 *   更多关于正则表达式可以参考:   https://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.aspx
    
                 *   或者是:http://www.cnblogs.com/youring2/archive/2009/11/07/1597786.html  (写得很清楚)
    
                 */
    
                Regex reg = new Regex("\d");
    
                Console.WriteLine(reg.IsMatch("12321"));
    
                #endregion
    
     
    
                #region 集合 List,Queue,Stack,Dictionary ,LinkedList (链表)
    
                //举例:
    
                List<int> list = new List<int> { 1, 2, 3, 4, 5, 6, 7 };
    
                list.ForEach((a) =>
    
                {
    
                    Console.WriteLine(a);
    
                });
    
                //或者:
    
                list.ForEach(delegate(int num)
    
                {
    
                    Console.WriteLine(num);
    
                });
    
     
    
                //队列:
    
                Queue<int> queue = new Queue<int>();
    
                //向队列中添加元素:
    
                queue.Enqueue(1);  //从尾部 添加数据
    
                int q = queue.Dequeue();  // 从头部添加
    
                Console.WriteLine("出队:{0}", q);
    
                //栈 Stack:
    
                Stack stack = new Stack();
    
                stack.Push(1); //添加
    
                Console.WriteLine("返回栈顶元素:{0}", stack.Peek());//返回栈顶元素
    
                /* 其它:并发集合...
    
                    以下几个为线程安全的集合:IProducerConsumerCollection<T>
    
                    ,ConcurrentQueue<T>......BlockingCollection<T>
    
                 */
    
                #endregion
    
     
    
                #region Linq、动态语言扩展、内存管理与指针
    
                //linq 并行运算AsParallel
    
                var sum = (from f in list.AsParallel() where f < 3 select f);
    
                //动态语言:dynamic
    
                #endregion
    
            }
    

      

    //未完待续...

  • 相关阅读:
    丛铭俣 160809324 (作业5)
    丛铭俣 160809324 (作业4)
    丛铭俣 160809324 (作业3)
    丛铭俣 160809324 (作业2)
    系统设计的一些原则
    计算输入框的字符长度
    DateTime.ToLongDateString
    邮箱发送验证码
    .net core中加入日志
    .net core 将类库项目转移到一个新建的文件夹下面
  • 原文地址:https://www.cnblogs.com/luo-super/p/4872356.html
Copyright © 2011-2022 走看看