[LINQ] Element 로 어떤 동작 실행하는 경우 예제
Performing Operations on Source Elements
An output sequence might not contain any elements or element properties from the source sequence. The output might instead be a sequence of values that is computed by using the source elements as input arguments. The following simple query, when it is executed, outputs a sequence of strings whose values represent a calculation based on the source sequence of elements of type double.
Note |
---|
Calling methods in query expressions is not supported if the query will be translated into some other domain. For example, you cannot call an ordinary C# method in LINQ to SQL because SQL Server has no context for it. However, you can map stored procedures to methods and call those. For more information, see Stored Procedures [LINQ to SQL]. |
class FormatQuery { static void Main() { // Data source. double[] radii = { 1, 2, 3 }; // Query. IEnumerable<string> query = from rad in radii select String.Format("Area = {0}", (rad * rad) * 3.14); // Query execution. foreach (string s in query) Console.WriteLine(s); // Keep the console open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: Area = 3.14 Area = 12.56 Area = 28.26 */
'Language > C#' 카테고리의 다른 글
[LINQ] sql 에는 없는 키워드 - let (1043) | 2015.04.28 |
---|---|
[LINQ] Basic LINQ Query Operations (C#) (6) | 2015.04.28 |
[LINQ] 메모리상의 객체를 XML 로 변환하기 (671) | 2015.04.28 |
[LINQ] subset 부분 집합 구하기 (6) | 2015.04.28 |
[LINQ] 여러 인풋을 하나의 시퀀스로 Join 하기 (6) | 2015.04.28 |