Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Convert the letters of a given string into alphabetical order

C# Sharp Basic: Exercise-73 with Solution

Write a C# Sharp program to convert the letters of a given string (same case-upper/lower) into alphabetical order.

Sample Solution:

C# Sharp Code:

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Original string: PHP");
            Console.WriteLine("Convert the letters of the said string into alphabetical order: " + test("PHP"));
            Console.WriteLine("Original string: javascript");
            Console.WriteLine("Convert the letters of the said string into alphabetical order: " + test("javascript"));
            Console.WriteLine("Original string: python");
            Console.WriteLine("Convert the letters of the said string into alphabetical order: " + test("python"));
        }
        public static string test(string str1)
        {
            return new string(str1.OrderBy(x => x).ToArray());
        }
    }
}

Sample Output:

Original string: PHP
Convert the letters of the said string into alphabetical order: HPP
Original string: javascript
Convert the letters of the said string into alphabetical order: aacijprstv
Original string: python
Convert the letters of the said string into alphabetical order: hnopty

Flowchart:

Flowchart: C# Sharp Exercises - Convert the letters of a given string into alphabetical order.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to check whether the average value of the elements of a given array of numbers is a whole number or not.
Next: Write a C# Sharp program to check the length of a given string is odd or even. Return 'Odd length' if the string length is odd otherwise 'Even length'.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.