[c#] Is there a simple way that I can sort characters in a string in alphabetical order

I have strings like this:

var a = "ABCFE";

Is there a simple way that I can sort this string into:

ABCEF

Thanks

This question is related to c# string sorting

The answer is


You can use this

string x = "ABCGH"

char[] charX = x.ToCharArray();

Array.Sort(charX);

This will sort your string.


new string (str.OrderBy(c => c).ToArray())

Yes; copy the string to a char array, sort the char array, then copy that back into a string.

static string SortString(string input)
{
    char[] characters = input.ToArray();
    Array.Sort(characters);
    return new string(characters);
}