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.49028c.com/youring2/archive/2009/11/07/1597786.html (寫得很清楚) */ Regex reg = new Regex("http://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 }
//未完待續...
新聞熱點
疑難解答