Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,094 questions

40,775 answers

573 users

How to sort string array in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[] { "java", "php", "c", "c++", "c#" };

            Array.Sort(arr);

            foreach (string s in arr) {
                Console.WriteLine(s);
            }
        }
    }
}


/*
run:
      
c
c#
c++
java
php
  
*/

 





answered Aug 6, 2018 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[] { "python", "java", "php", "c", "c++", "c#" };

            var sort = from s in arr
                       orderby s
                       select s;

            foreach (string str in sort) {
                Console.WriteLine(str);
            }
        }
    }
}


/*
run:
      
c
c#
c++
java
php
python
  
*/

 





answered Aug 6, 2018 by avibootz

Related questions

1 answer 52 views
1 answer 66 views
66 views asked Oct 31, 2020 by avibootz
1 answer 80 views
80 views asked Aug 15, 2018 by avibootz
1 answer 16 views
...