The application of LINQ in Array,list,dictionary
Today in the actual work need to sort array,list,dictionary, try LINQ, found very useful, the code is as follows:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Text.RegularExpressions;6 7 namespaceTest8 {9 class ProgramTen { One Static voidMain (string[] args) A { -Console.WriteLine ("Hello world!"); - stringInputstr ="ABF DCF Frgt"; theInputstr = Regex.Replace (Inputstr.trim (),"{2,}"," "); - Console.WriteLine (INPUTSTR); - - int[] num = {1,2,3,4,5,5,6,1,3,2 }; + //array.sort (num); - varNums = ( fromLinchNum byLSelectl). ToArray (); +Console.Write ("array:\n"); A foreach(intIinchnums) at Console.Write (i.ToString ()); -Console.Write ("\nlist:\n"); -list<int> list =Newlist<int> () {1,2,1,9,3,2,7 }; -List = ( fromLinchList byLSelectl). ToList (); - foreach(varLinchlist) - Console.Write (l); indictionary<int,int> counts =Newdictionary<int,int> () {{1,2},{2,3},{3,1}}; - //var results = (from d in counts by D.value descending select D). Take (2). ToDictionary (k = k.key, V = v.value); to varResults = ( fromDinchCounts byD.value DescendingSelectD.key). Take (2). ToArray (); +Console.Write ("\ndictionary:\n"); - foreach(varDinchresults) the Console.WriteLine (d); * $ Console.readkey ();Panax Notoginseng } - } the}
View Code
The application of LINQ in Array,list,dictionary