星空网 > 软件开发 > ASP.net

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 字符串正则表达式

            //------基础----------------

            /* 元字符:  .:表示匹配除换行以外的任意字符  \b:匹配单词开始或者结束  \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

        }

//未完待续...




原标题:C#基础知识记录一

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

销售额暴涨22倍!自行车出海市场全线上扬:https://www.kjdsnews.com/a/556666.html
二次裁员潮来了!深圳大卖做培训自救……:https://www.kjdsnews.com/a/556667.html
在线客服延长服务时间至21点,了解这波提效调整助您抢赢9.9:https://www.kjdsnews.com/a/556668.html
知识产权系列:欧盟商标如何转为单国商标:https://www.kjdsnews.com/a/556669.html
中小卖家库存管理如何打理?:https://www.kjdsnews.com/a/556670.html
封号潮还没结束,亚马逊审查紧接而上?卖家们要小心了:https://www.kjdsnews.com/a/556671.html
美国版权小知识-哪些作品能够登记美国版权?:https://www.kjdsnews.com/a/1836627.html
俄罗斯汽车企业进口东风汽车零部件组装雪铁龙汽车:https://www.kjdsnews.com/a/1836628.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流