I have a little problem with sorting out a list using an implementation of IComparer.
public struct VAL
{
public int i;
public string s;
}
public struct INFO
{
public string name;
public VAL val;
public string address;
}
public class ListSorter:IComparer<INFO>
{
public enum SORT_TYPE{BYNAME, BYVAL,BYADDRESS};
public int Compare(INFO i1, INFO i2)
{
switch(sortType)
{
case SORT_TYPE.BYNAME;
return string.Compare(i1.name, i2.name);
case SORT_TYPE.BYADDRESS:
return string.Compare(i1.address, i2.address);
case SORT_TYPE.BYVAL:
{
??????
}
}
}
}
The comparison function in the class ListSorter is an example of how I am comparing strings in the given INFO struct. But I don’t know how to sort the list based on the VAL struct information members
Normally you would do something like:
You first compare the
iand if they are equal you compare thes(or the opposite, the order must be selected by you).