The application of LINQ in Array,list,dictionary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.