Comparing objects - how?

  • Thread starter Thread starter Katit
  • Start date Start date
K

Katit

I know I read about it somewhere when studying, but can't come up with
keywords to search on this topic.

I need to be able to compare objects like

if (A < B) {}...

This will be used to sort/position objects in UI.

Objects have set of properties and based on values of those specific
properties I want to be able to compare those objects..


I know it's possible, please give me some pointers.
 
Katit said:
I know I read about it somewhere when studying, but can't come up with
keywords to search on this topic.

I need to be able to compare objects like

if (A < B) {}...

This will be used to sort/position objects in UI.

Objects have set of properties and based on values of those specific
properties I want to be able to compare those objects..


I know it's possible, please give me some pointers.

Implement the IComparable<T> interface in the class, or create a
comparer class that implements IComparer<T>, depending on how you are
going to sort the objects. The List<T>.Sort method for example can use
either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top