From 20bf50361a6030a55a1a4592b4b4741ae2f4405d Mon Sep 17 00:00:00 2001 From: chen-jiaxinxxx <2971973423@qq.com> Date: Mon, 22 May 2023 17:22:53 +0800 Subject: [PATCH 1/3] 1 --- ...72\347\241\200\347\254\224\350\256\260.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "44\351\231\210\345\230\211\351\221\253/20230522-net\351\233\206\345\220\210\345\237\272\347\241\200\347\254\224\350\256\260.md" diff --git "a/44\351\231\210\345\230\211\351\221\253/20230522-net\351\233\206\345\220\210\345\237\272\347\241\200\347\254\224\350\256\260.md" "b/44\351\231\210\345\230\211\351\221\253/20230522-net\351\233\206\345\220\210\345\237\272\347\241\200\347\254\224\350\256\260.md" new file mode 100644 index 0000000..5e228e6 --- /dev/null +++ "b/44\351\231\210\345\230\211\351\221\253/20230522-net\351\233\206\345\220\210\345\237\272\347\241\200\347\254\224\350\256\260.md" @@ -0,0 +1,51 @@ +### 三种集合排序法 +``` +var intList = new List() { 6,1,2,4,80,44,7,9,8}; + +第一种 + +var list = new List(); +foreach (var item in intList) +{ + if(item > 3 && item % 2 == 0){ + list.Add(item); + } +} + +list.Sort(); + +foreach (var item in list) +{ + Console.WriteLine($"{item}"); +} + +第二种 + +var cjx = from n in intList + where n >3 && n % 2 == 0 + orderby n + select n; +foreach (var item in cjx) +{ + Console.WriteLine($"{item}"); +} + +第三种 + +var test = intList.Where(n => n >3 && n % 2 == 0).OrderBy(n => n).Select(n => n); +foreach (var item in test) +{ + Console.WriteLine($"{item}"); +} +``` +### 统计随机数出现的次数 +``` +var rnd = new Random(1000); +var arr = Enumerable.Range(0,100).Select(_ => rnd.Next(0,10)); + +var nxx = arr.GroupBy(n => n).Select(n => new{key = n.Key, count = n.Count()}); +foreach (var item in nxx) +{ + Console.WriteLine("{0}出现了{1}次",item.key,item.count); +} +``` \ No newline at end of file -- Gitee From dd66d4c0042e0940540c7b0b466aaf991c8fa78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E9=91=AB?= <2971973423@qq.com> Date: Tue, 23 May 2023 09:38:30 +0000 Subject: [PATCH 2/3] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈嘉鑫 <2971973423@qq.com> --- .../\351\242\230\347\233\256.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" diff --git "a/44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" "b/44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" new file mode 100644 index 0000000..9a3ca54 --- /dev/null +++ "b/44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" @@ -0,0 +1,81 @@ +1. +``` +var lst = new List(){1,2,3,4,5,6,7,8,9,0}; +//筛选偶数,并从小到大排序 + +var list = lst.Select(n=>n).Where(n=>n%2==0).OrderBy(n=>n); +foreach (var item in list) +{ + Console.WriteLine("{0}",item); +} +``` +2. +``` +//统计随机数出现的次数。 +var rnd = new Random(1000); +var arr = Enumerable.Range(0,100).Select(_ => rnd.Next(0,10)); + +var list = arr.GroupBy(n=>n).Select(n=>new{n.Key,Value=n.Count()}); + +foreach (var item in list) +{ + Console.WriteLine("{0},{1}",item.Key,item.Value); +} +``` +3. +``` +var str = new string[]{"rust","csharp","python","java","c","golang"}; +//统计每个字符出现的次数,并且按照出现次数频率从高到低排序 +var lst = from n in str + from c in n + group c by c into g + orderby g.Count() descending + select new {g.Key, Value=g.Count()}; + + +//使用扩展方法(链式)实现 + +var list = str.SelectMany(n=>n).GroupBy(n=>n).OrderByDescending(n=>n.Count()).Select(n=>new{n.Key,Value=n.Count()}); + +foreach (var item in list) +{ + Console.WriteLine("{0}出现了{1}次",item.Key,item.Value); +} +``` +4. +``` +string pic1 = "4b069d702e7fec0dc06cf5815ece8503.jpeg"; +string pic2 = "4b069d702e7fec0dc06cf5815esn7005.jpeg"; +string pic3 = "4b069d702e7fec0dc06cf5815ets6730.jpeg"; +//使用AsParallel模拟同步下载三张图片 +//结果: +/* + pic1 下载完成 + pic3 下载完成 + pic2 下载完成 +*/ + +var list = new Dictionary(){{"pic1",pic1},{"pic2",pic2},{"pic3",pic3}}; + +var lst = list.AsParallel().Select(n=>n); + +foreach (var item in lst) +{ + Console.WriteLine("{0}下载成功",item.Key); +} +``` +5. +``` + +for (int i = 0; i < 5; i++) +{ + for (int j = 0; i < 4; i++) + { + for (int k = 0; i < 3; i++) + { + Console.WriteLine($"{i},{j},{k}"); + } + } +} +//使用linq打印所有排列组合 +``` \ No newline at end of file -- Gitee From 11a85bceaab9160c9650644ce2f62f5ec1c4209d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E9=91=AB?= <2971973423@qq.com> Date: Tue, 23 May 2023 09:38:54 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2044=E9=99=88?= =?UTF-8?q?=E5=98=89=E9=91=AB/=E9=A2=98=E7=9B=AE.md=20=E4=B8=BA=2044?= =?UTF-8?q?=E9=99=88=E5=98=89=E9=91=AB/20230523-net=E9=A2=98=E7=9B=AE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230523-net\351\242\230\347\233\256.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" => "44\351\231\210\345\230\211\351\221\253/20230523-net\351\242\230\347\233\256.md" (100%) diff --git "a/44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" "b/44\351\231\210\345\230\211\351\221\253/20230523-net\351\242\230\347\233\256.md" similarity index 100% rename from "44\351\231\210\345\230\211\351\221\253/\351\242\230\347\233\256.md" rename to "44\351\231\210\345\230\211\351\221\253/20230523-net\351\242\230\347\233\256.md" -- Gitee