ShovelingLife 2022. 6. 7. 12:53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
 
namespace ConsoleApp8
{
    class Profile
    {
        public int height;
        public string name = null;
    }
 
    class Program
    {
        // foreach로 해당 데이터들 접근가능, 람다식 형식이여야됨.
        // from : 데이터를 어디서 가져오는지 지정해주는 메소드, 대체 메소드 없음.
        // where : 가져온 데이터들에 조건을 거는 메소드, .Where()로 대체 가능.
        // let : 
        // orderby : 가져온 데이터들을 정리해주는 메소드, ascending > 오름차순, descending > 내림차순, 
        //                                            .OrderBy(),           .OrderByDescending()로 대체 가능.
        // select : 가져온 데이터들을 뽑아주는 메소드 (값 변경 가능), .Select()로 대체 가능.
        // group : 
        static void Main(string[] args)
        {
            Profile[] arr_profile = { new Profile{ height = 175, name = "가" },
                                      new Profile{ height = 160, name = "나" },
                                      new Profile{ height = 155, name = "다" },
                                      new Profile{ height = 190, name = "라" },
                                      new Profile{ height = 185, name = "마" }
                };
            var profiles = from    profile in arr_profile
                           where   profile.height < 175
                           orderby profile.height
                           select new
                           {
                               nn = profile.name,
                               hh = profile.height
                           };
            foreach (var item in profiles)
                    Console.WriteLine($"{item.nn}");
 
            IEnumerable<IGrouping<bool, Profile>> listProfile = arr_profile.OrderBy(x => x.height)
                                                                           .GroupBy(x => x.height < 175);
 
            foreach (var Group in listProfile)
                     Console.WriteLine($"{Group.Key}");
 
            int[] arr = { 10, 20, 30, 4, 7, 12, 21 };
 
            var tempResult = from    item in arr
                             where   item >= 10
                             orderby item descending
                             select  item;
 
            IEnumerable<int> result3 = arr.Where((x) => x >= 10)
                                          .OrderByDescending((x) => x)
                                          .Select(x => x * 5);
 
            foreach (var item in result3)
                     Console.WriteLine($"{item}");
 
            IEnumerable<int> tempResult2 = from item in arr
                                           select item;
 
            int[] tempArray = tempResult2.ToArray();
 
            foreach(var item in tempResult2)
                    Console.WriteLine($"{item}");
 
            List<int> tempList = new List<int>(arr);
            tempList.Sort();
        }
    }
}