[LINQ] subset 부분 집합 구하기

Posted by RAY.D
2015. 4. 28. 13:22 Language/C#
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.




Selecting a Subset of each Source Element

There are two primary ways to select a subset of each element in the source sequence:

  1. To select just one member of the source element, use the dot operation. In the following example, assume that a Customer object contains several public properties including a string named City. When executed, this query will produce an output sequence of strings.

    var query = from cust in Customers
                select cust.City;
    
  2. To create elements that contain more than one property from the source element, you can use an object initializer with either a named object or an anonymous type. The following example shows the use of an anonymous type to encapsulate two properties from each Customer element:

    var query = from cust in Customer
                select new {Name = cust.Name, City = cust.City};
    

For more information, see Object and Collection Initializers (C# Programming Guide) and Anonymous Types (C# Programming Guide).