using System.Collections;
public class AlphaNumericComparer : IComparer
public int Compare(object x, object y)
while (marker1 < len1 && marker2 < len2)
var space1 = new char[len1];
var space2 = new char[len2];
} while (char.IsDigit(ch1) == char.IsDigit(space1[0]));
} while (char.IsDigit(ch2) == char.IsDigit(space2[0]));
var str1 = new string(space1);
var str2 = new string(space2);
if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
var thisNumericChunk = int.Parse(str1);
var thatNumericChunk = int.Parse(str2);
result = thisNumericChunk.CompareTo(thatNumericChunk);
result = str1.CompareTo(str2);
public static void Main()
String[] defaultSortedArray = {"_DB24C_0", "_DB24C_1", "_DB24C_2", "_DB24C_3", "_DB24C_10","_DB24C_4", "_DB24C_11"};
String[] newSortedArray = {"_DB24C_0", "_DB24C_1", "_DB24C_2", "_DB24C_3", "_DB24C_10","_DB24C_4", "_DB24C_11"};
Console.WriteLine("Default Sorted String Array:\n");
Array.Sort(defaultSortedArray);
DisplayArray(defaultSortedArray);
Console.WriteLine("\n\nNew Sorted String Array:\n");
Array.Sort(newSortedArray, new AlphaNumericComparer());
DisplayArray(newSortedArray);
static void DisplayArray(string[] arr)
foreach (string a in arr)