前言:最近项目比较忙,完全没有时间写下总结笔记,今天抽出时间来写下笔记,供写后台的你来做数据处理后台代码编写的参考。
一、分组
var GroupForList = numberList.GroupBy(x => x).ToDictionary(a => a.Key, b => b.ToList()).ToList();
二、交集、并集、差集
private static List numberList = new List () { 4,5,6,8,9,11 };private static List numberListTwo = new List () { 4,5,7,15,16,12 };public static void Main(string[] args) { var intersectList = numberList.Intersect(numberListTwo); //交集 var str = ""; var str2 = ""; var str3 = ""; foreach (var item in intersectList) { str += item+","; } var exceptList = numberList.Except(numberListTwo); //差集 foreach (var item in intersectList) { str2 += item + ","; } var unionList = numberList.Union(numberListTwo); //并集 foreach (var item in unionList) { str3 += item + ","; } Console.WriteLine("交集:" + str); Console.WriteLine("差集:" + str2); Console.WriteLine("并集:" + str3);}
三、递归
public static void Main(string[] args) { Recursion(1); }static int i = 0;private static void Recursion(int number) { Console.Write(number+","); var newnumber = number + i; i++; Thread.Sleep(1000); Recursion(newnumber); }
结语:这些就是用最简单的方法展示 各种后台数据处理时候可能要用到的方法啦。希望能帮助到初学者的你们