[C#] LINQ 예제~
// 데이타 형식 설정
class Profile
{
public string Name { get; set; }
public int Height { get; set; }
}
class Program
{
//delegate int LamdaTest(int[] arg);
////delegate int TestWhat(int[] arg);
//delegate int Result(int[] arg);
//delegate int Sum(int[] arg);
//delegate int Calculator2(int a, int b);
//delegate string Concatenate(string[] args);
static void Main(string[] args)
{
// 데이타 생성
Profile[] arrProfile = {
new Profile(){Name = "김Derrick", Height = 172},
new Profile(){Name = "김Boram", Height = 162},
new Profile(){Name = "김연", Height = 100},
new Profile(){Name = "김호", Height = 120},
new Profile(){Name = "김준", Height = 125}
};
Profile[] arrProfile_myFamily = {
new Profile(){Name = "박영", Height = 169},
new Profile(){Name = "김미", Height = 154},
new Profile(){Name = "김지", Height = 160}
};
// 조건만들기
var profiles = from profile in arrProfile
where profile.Height < 170
orderby profile.Height
select new
{
Name = profile.Name,
InchHeight = profile.Height * 0.393
};
// 하나씩 조건 출력
foreach (var n in profiles)
Console.WriteLine("{0}, {1}", n.Name, n.InchHeight);
댓글
댓글 쓰기