C#

88.C# - 프로젝션

Godffs 2009. 8. 20. 11:47
반응형
프로젝션 : 결과셋의 출력 형태를 테이터 소스와 다르게 변형하는 것입니다.
[재훈이형블로그]

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
public class Product {
    public string Name { get; set; }
    public int Quantity { get; set; } }

public class ProName {    public string ModelNAme { get; set; }    }

public class 프로젝션
{
    public static void Main(string[] args)
    {
        int[] data = { 3, 4, 5, 2, 1 };
        var query = from d in data where d % 2 == 0 select d; //결과유출

        IEnumerable<int> q = from d in data where d % 2 == 0 select d;

        int[] even = (from d in data where d % 2 == 0 select d).ToArray();

        List<int> lst = (from d in data where d % 2 == 0 select d).ToList();

        Product[] products = {
                                new Product{Name=".net", Quantity=1000},
                                new Product{Name="Java",Quantity=10} };

        // var pro = from p in product select p;
        // product 클레스를 ProName 클레스로 변형하여 출력
        IEnumerable<ProName> pro = from p in products select
                                                 new ProName { ModelNAme = p.Name };

        foreach (var item in pro) {
                             Console.WriteLine("{0}", item.ModelNAme);  }
    }
}

결과화면


반응형