CODEKILLER

반응형

> 문자열 길이의 오름차순으로 정렬하는 방법

Linq오름차순 정렬
Linq오름차순 정렬

using System.Xml.Linq;

public class Example
{
    public static void Main()
    {
        Console.Write("<< 1차 오름 정렬 >> \n");

        string[] words = { "this", "code", "killer", "very", "funny" };

        // 문자열 길이로 정렬.
        IEnumerable<string> query = from word in words
                                    orderby word.Length
                                    select word;

        foreach (string str in query)
            Console.WriteLine(str);


        Console.WriteLine(System.Environment.NewLine);
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
    }
}
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band