I have a class definition that looks like this:
public class MyObjectModel
{
public int ObjectID { get; set; }
//for when the user's data is split in 2 fields
public string FirstName { get; set; }
public string LastName { get; set; }
//for when the user's data is all in one field
public string FirstLastName { get; set; }
}
I have a list of these MyObjectModel and I want to sort them by name with a custom sort process because that involves checking if the data contains a LastName (in this case sort using the LastName) or just FirstLastName (in this case I’m going to break the string and sort on the second term, if there’s one, or just the whole string if there’s only one word.)
I’m not sure on two things:
- should I use
IComparerorIComparable? - Once it determines the order of the sort (I can do that), how do I make it so that the output of the method is a list of ints representing
ObjectID.
Use Linq:
FunctionWhichReturnsNameForSortcan be implemented in another class, or an extension, or as a member.