90. 프로젝션
.NET프로그래밍/C# 3.5 SP1 2009. 8. 20. 11:34 |using System;
using System.Linq;
using System.Collections.Generic;
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()
{
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="닷넷", Quantity=1000},
new Product{Name="자바", Quantity=10}
};
//var pro = from p in products select p; //[1]
IEnumerable<ProName> pro = from p in products
select new ProName { ModelName = p.Name }; //[2] 다른 클래스의 프로퍼티로 변환시켜 출력
foreach (var item in pro)
{
Console.WriteLine("{0}", item.ModelName); // 다른 개체형으로 변환
}
}
}
'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글
C# 단어 및 수업 내용 복습(정리) ==> 테스트 관련 (0) | 2009.08.26 |
---|---|
105. 파일처리 (0) | 2009.08.24 |
(테스트) 체중 관리 프로그램 (0) | 2009.08.20 |
89. LINQ - 그룹알고리즘 (0) | 2009.08.19 |
88. LINQ - 병합 (0) | 2009.08.19 |