CODEKILLER

반응형

IEnumerable<T> 사용법.
IEnumerable<T> 사용법.

using System.Xml.Linq;

public class Example
{
    public static void Main()
    {
        Console.Write("IEnumerable<T> 의 사용 \n");

        List<Customer> customers = new List<Customer>();
        customers.Add(new Customer() { City = "Seoul", FirstName = "Code", LastName = "Killer" });
        customers.Add(new Customer() { City = "Busan", FirstName = "Dragon", LastName = "Ball" });

        IEnumerable<Customer> customerQuery =
            from cust in customers
            where cust.City == "Seoul"
            select cust;

        // 필터링 기능 사용시에는 LINQ Where절에 논리식 적용.
        // where cust.City == "Seoul" && cust.FirstName == "Code"

        foreach (Customer customer in customerQuery)
        {
            Console.WriteLine(customer.LastName + ", " + customer.FirstName);
        }
    }
}


public class Customer
{
    public string City { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band