26 May 2016

Sort in C# Array string list

list.Sort();
Sort List C# 2016
class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<String>(){
             "Korea",
             "Vietnam",
             "Austrian",
                    "Japan",
             "Berlin"
            };
            list.Sort();
            foreach(string s in list){
                Console.WriteLine(s);
            }
            Console.ReadLine();
        }

    }

list.Sort();  >> array
Sort List C# 2016
class Program
    {
        static void Main(string[] args)
        {
            string[] array = { "Korea", "Japan","Berlin", "Vietnam" };
            List<string> list = new List<string>(array);
            list.Sort();

            Console.WriteLine(string.Join(",", array));
            Console.WriteLine(string.Join(",", list));
            Console.ReadLine();
        }

    }

Desc >> giảm Array
Sort C# 2016
class Program
    {
        static void Main(string[] args)
        {
            string[] a = new string[]
         {
                 "French",
                 "Korea",
                 "European",
                 "Japan",
                 "Vietnamese"
         };
            var desc = from s in a
                       orderby s descending
                       select s;

            foreach (string c in desc)
            {
                Console.WriteLine(c);
            }
            Console.ReadLine();
        }

    }

Asc >> tăng Array
Sort C# 2016
class Program
    {
        static void Main(string[] args)
        {
            string[] a = new string[]
             {
                 "Indonesian",
                 "Korean",
                 "Japanese",
                 "English",
                 "German"
             };
            var asc= from s in a
                       orderby s
                       select s;

            foreach (string c in asc)
            {
                Console.WriteLine(c);
            }
            Console.ReadLine();
        }

    }

Array.Sort(); Array
Sort C# 2016
class Program
    {
        static void Main(string[] args)
        {
            string[] a = new string[]
         {
             "Egyptian",
             "Indian",
             "American",
             "Chinese",
             "Filipino",
         };
            Array.Sort(a);
            foreach (string s in a)
            {
                Console.WriteLine(s);
            }
            Console.ReadLine();
        }

    }

Array.Sort(); Array
Sort C# 2016
class Program
    {
        static void Main(string[] args)
        {
            char[] array = { 'z', 'a', 'b' }; // Input array.
            Array.Sort<char>(array);          // Call sort.
            foreach (var c in array)
            Console.WriteLine(c);
            Console.ReadLine();
        }

    }
         

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang