A
Arulraja
Hello,
I have a custom collection object. each instance has FirstName and
LastName. I want to sort this object collection by Last Name and First
Name(ie if the last names are same I want to sub sort it by First
Name).
I know how to sort it by one value?(last Name) I am using the
following code for this.It is working fine.
public int CompareTo(Person obj, SortOrder sort, bool sortAscending)
{
int retVal = 0;
switch (sort)
{
case SortOrder.LastName:
{
retVal = this.LastName.CompareTo(obj.LastName);
if (sortAscending)
return retVal;
else
return (-1 * retVal);
}
//This Part is not working
------------------------------------------------------------------
case SortOrder.LastNameAndFirstName:
{
retVal = this.LastName.CompareTo(obj.LastName);
retVal = this.FirstName.CompareTo(obj.FirstName);
if (sortAscending)
return retVal;
else
return (-1 * retVal);
}
------------------------------------------------------------------
}
return retVal;
}
Can somebody direct me on this.
Thanks
Arul
I have a custom collection object. each instance has FirstName and
LastName. I want to sort this object collection by Last Name and First
Name(ie if the last names are same I want to sub sort it by First
Name).
I know how to sort it by one value?(last Name) I am using the
following code for this.It is working fine.
public int CompareTo(Person obj, SortOrder sort, bool sortAscending)
{
int retVal = 0;
switch (sort)
{
case SortOrder.LastName:
{
retVal = this.LastName.CompareTo(obj.LastName);
if (sortAscending)
return retVal;
else
return (-1 * retVal);
}
//This Part is not working
------------------------------------------------------------------
case SortOrder.LastNameAndFirstName:
{
retVal = this.LastName.CompareTo(obj.LastName);
retVal = this.FirstName.CompareTo(obj.FirstName);
if (sortAscending)
return retVal;
else
return (-1 * retVal);
}
------------------------------------------------------------------
}
return retVal;
}
Can somebody direct me on this.
Thanks
Arul