I have a class
class grpa
{
public string file_name { get; set; }
public string folder_name { get; set; }
}
I also have 2 lists of strings.
List<string> actualfiles = new List<string>();
List<string> directoryfiles= new List<string>();
I'm using an enumerator to create a list of objects of type grpa
IEnumerator enume1 = actualfiles.GetEnumerator();
IEnumerator enume2 = directoryfiles.GetEnumerator();
List<grpa> grp_list = new List<grpa>();
while ((enume1.MoveNext()) && (enume2.MoveNext()))
{
grp_list.Add(new grpa
{
file_name = enume1.Current.ToString(),
folder_name = enume2.Current.ToString()
});
}
I would like to sort the list after file_name using natural sort:
I have this:
public static class SafeNativeMethods
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
public static extern int StrCmpLogicalW(string psz1, string psz2);
}
public sealed class NaturalStringComparer : IComparer<string>
{
#region IComparer<string> Members
public int Compare(string x, string y)
{
return SafeNativeMethods.StrCmpLogicalW(x, y);
}
#endregion
}
If it would have been a normal string list I could have sort it using: actualfiles.Sort(new NaturalStringComparer());
But how can I sort grp_list
after file_name
?
You can wrap NaturalString comparer with: