Blog Content

    티스토리 뷰

    85.C# - 쿼리식반환값처리

    반응형
    쿼리식 반환값 처리 예제입니다.

    Program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class 쿼리식반환값처리
    {
        public static void Main()
        {
            int[] data = { 3, 5, 4, 2, 1 };

            //[!] Process
            int[] sorted = (from d in data orderby d select d).ToArray(); //배열

            for(int i=0; i< sorted.Length; i++) {
                Console.WriteLine("{0}",sorted[i]);
            }
            List<int> lst = ( from d in data orderby d
                                             descending select d).ToList(); //컬렉션


            for(int i=0; i<lst.Count; i++)
    {
                Console.WriteLine("{0}",lst[i]);
            }
        }
    }

    결과화면


    반응형

    Comments