[C#] LINQ- 두번재 연습!


class Profile
    {
        public string Name { get; set; }
        public int Height { get; set; }

    }




    class Program
    {
     

        static void Main(string[] args)
        {

            Profile[] arrProfile =
            {
                new Profile() { Name = "정우성", Height = 186},
                new Profile() { Name = "김태희", Height = 155},
                new Profile() { Name = "고현정", Height = 145},
                new Profile() { Name = "이문세", Height = 232},
                new Profile() { Name = "하하", Height = 165}
            };

            var listProfile = from profile in arrProfile
                              orderby profile.Height
                              group profile by profile.Height < 177 into g
                              select new { Groupkey = g.Key, Profiles = g };
            foreach (var Group in listProfile)
            {
                Console.WriteLine("- 177cm 미만 ? : {0}", Group.Groupkey);
                foreach (var profile in Group.Profiles)
                {
                    Console.WriteLine("{0}, {1}", profile.Name, profile.Height);
                }
            }

}

생각보다 더 재밋다....................ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

댓글

이 블로그의 인기 게시물

[C# Winform 예제] ScreenSaver 스크린세이버 만들기

아 정말 이사람 IELTS 관한 비법 글은.. 정말 공감10000%

Vocabulary for IELTS (2000 words) advanced level.