. Net linq Data Conversion

Source: Internet
Author: User

  • Convert data using LINQ
  • Join multiple inputs to an output sequence
 Student{      First { ; ; }      Last {; ;}      ID { ; ; }      Street { ; ; }      City { ; ; }     List<> Scores;} Teacher{      First { ; ; }      Last { ; ; }      ID { ; ; }       City { ; ; }}
 DataTransformations{      Main()    {        List<Student> students =  List<Student>()        {             Student {First=,                Last=,                 ID=111,                 Street=,                City=,                Scores=  List<> {97, 92, 81, 60}},             Student {First=,                Last=,                 ID=112,                Street=,                City=,                Scores=  List<> {75, 84, 91, 39}},             Student {First=,                Last=,                ID=113,                Street=,                City=,                Scores=  List<> {88, 94, 65, 91}},        };        List<Teacher> teachers =  List<Teacher>()        {                             Teacher {First=, Last=, ID=945, City = },             Teacher {First=, Last=, ID=956, City = },             Teacher {First=, Last=, ID=972, City = }        };         peopleInSeattle = ( student  students                     student.City ==                      student.Last)                    .Concat( teacher  teachers                             teacher.City ==                              teacher.Last);        Console.WriteLine();         ( person  peopleInSeattle)        {            Console.WriteLine(person);        }        Console.WriteLine();        Console.ReadKey();    }}
  • Select a subset of each source element
  • Convert objects in memory to XML
 XMLTransform{      Main()    {                    List<Student> students =  List<Student>()        {             Student {First=, Last=, ID=111, Scores =  List<>{97, 92, 81, 60}},             Student {First=, Last=, ID=112, Scores =  List<>{75, 84, 91, 39}},             Student {First=, Last=, ID=113, Scores =  List<>{88, 94, 65, 91}},        };         studentsToXML =  XElement(,             student  students             x = String.Format(, student.Scores[0],                    student.Scores[1], student.Scores[2], student.Scores[3])              XElement(,                        XElement(, student.First),                        XElement(, student.Last),                        XElement(, x)                    )                 );         Console.WriteLine(studentsToXML);        Console.WriteLine();        Console.ReadKey();    }}
  • Perform operations on the Source Element
 FormatQuery{      Main()    {                    [] radii = { 1, 2, 3 };        IEnumerable<> query =             rad  radii             String.Format(, (rad * rad) * 3.14);         ( s  query)            Console.WriteLine(s);        Console.WriteLine();        Console.ReadKey();    }}

Related Article

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.