Question: I want to this list

```
A
B
C
111
11
123
1
42
5

```

To be sorted 

```
1
5
11
42
111
123
A
B
C

```

By default, it sorts numbers like strings (So, it goes 1,11,111,123,42,5),
But I want to sort numbers like numbers, and than strings that are not numbers.

Is there clean solution to sort it like above?

It is a list of objects, and object has several properties, one of which is a this string.

Answer: 
I wrote this `IComparer` implementation a few months back to handle something like this. I think it will do what you want by default, though it is built to handle more complex cases where number/letter groups are separated by delimiters that also need to be sorted atomically. You should be able to adjust it to your needs.

```
public class SemanticComparer : IComparer<string>
{
    private static Regex _splitter = new Regex("\\W+");

    public int Compare(string x, string y)
    {
        string[] partsX = _splitter.Split(x);
        string[] partsY = _splitter.Split(y);

        int shortest = Math.Min(partsX.Length, partsY.Length);

        for (int index = 0; index < shortest; index++)
        {
            int intX, intY;
            int result;

            if (int.TryParse(partsX[index], out intX) && int.TryParse(partsY[index], out intY))
            {
                result = intX.CompareTo(intY);
            }
            else
            {
                result = string.Compare(partsX[index], partsY[index], StringComparison.Ordinal);
            }

            if (result != 0)
            {
                return result;
            }
        }

        return 0;
    }
}

```

You can sort your list with it like this:

```
MyList.Sort(new SemanticComparer());

```
I've created a solution for this. I've divided the `list` into two part then sort and concat. Please check below:

```
public List<ListItem> getSortedList()
{
    int dummy = 0;

    List<ListItem> list = new List<ListItem>();
    list.Add(new ListItem() { Item = "A" });
    list.Add(new ListItem() { Item = "B" });
    list.Add(new ListItem() { Item = "C" });
    list.Add(new ListItem() { Item = "111" });
    list.Add(new ListItem() { Item = "11" });
    list.Add(new ListItem() { Item = "123" });
    list.Add(new ListItem() { Item = "1" });
    list.Add(new ListItem() { Item = "42" });
    list.Add(new ListItem() { Item = "5" });

    var listNumber = list.Where(m => int.TryParse(m.Item, out dummy)).ToList().OrderBy(m => Convert.ToInt16(m.Item)).ToList();
    var listString = list.Where(m => !int.TryParse(m.Item, out dummy)).ToList().OrderBy(m => m.Item).ToList();

    var sortedList = listNumber.Concat(listString).ToList();

    return sortedList;
}

```

You can run this in [DotNetFiddle](https://dotnetfiddle.net/rfs3du).