Barefoot learning LINQ (011): perform operations on Source Elements

Source: Internet
Author: User

Http://u.115.com/file/f2ce0eeb6 demo

The output sequence may not contain any element or element attribute of the source sequence. The output may be a sequence of values calculated by using the source element as an input parameter. When executing the following simple query, this query will output a string sequence, which indicates the calculation based on the source sequence of the double type element.
Description
If a query is converted to another domain, you cannot call a method in a query expression. For example, you cannot call a general C # method in LINQ to SQL, because SQL server does not have the context of this method. However, you can map stored procedures to methods and then call methods.

// Data source.   double[] Radii = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };     // Results.   IEnumerable<string> Results =       from Rad in Radii       select String.Format("Area = {0}", (Rad * Rad) * 3.14);     // Results execution.    foreach (string Result in Results)       Console.WriteLine(Result);     // Keep the console open in debug mode.   Console.WriteLine("Press any key to exit.");   Console.ReadKey()  // Data source.double[] Radii = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// Results.IEnumerable<string> Results =    from Rad in Radii    select String.Format("Area = {0}", (Rad * Rad) * 3.14);// Results execution. foreach (string Result in Results)    Console.WriteLine(Result);// Keep the console open in debug mode.Console.WriteLine("Press any key to exit.");Console.ReadKey() 

The output is as follows:

Area = 3.14   Area = 12.56   Area = 28.26   Area = 50.24   Area = 78.5   Area = 113.04   Area = 153.86   Area = 200.96   Area = 254.34 

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.