c#數據處理總結(分組、交並差與遞歸)
阿新 • • 發佈:2018-06-15
數據 cti ict AR 交集 src lee 9.png 前言
前言:最近項目比較忙,完全沒有時間寫下總結筆記,今天抽出時間來寫下筆記,供寫後臺的你來做數據處理後臺代碼編寫的參考。
一、分組
var GroupForList = numberList.GroupBy(x => x).ToDictionary(a => a.Key, b => b.ToList()).ToList();
二、交集、並集、差集
private static List<int> numberList = new List<int>() { 4,5,6,8,9,11 }; privatestatic List<int> numberListTwo = new List<int>() { 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); }
結語:這些就是用最簡單的方法展示 各種後臺數據處理時候可能要用到的方法啦。希望能幫助到初學者的你們
c#數據處理總結(分組、交並差與遞歸)