• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Best way to sort objects on multiple properties in C#

archcommus

Diamond Member
Hey guys,

I have a C# web application I'm working on. I have a GridView object where each row is an object (class) I've made with various properties. I know I can have the object implement IComparable, write a CompareTo function in the class, and then sort an array of this object using Array.Sort(), but I want to be able to sort the object on different properties, for example name, or type, or date, so that users can the use the column headers in the GridView to sort. I've read a number of different ways to go about this, some using private internal sorting classes and then IComparer, others using refraction and such. Which method would you recommend?

Thanks.
 
Back
Top