Jump to content

sort() method for list of objects?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
phil333

phil333

    Newbie

  • Members
  • Pip
  • 5 posts
Why when using a sort method on a list of objects do you need to have a Icomparable method in the corresponding class?

List<students> studentList = new List<Student>();
//add objects to list.
studentList.Sort();

When sorting an array for example this is not required?

#2
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
Lists are more elegant than arrays. They can do stuff for you, instead arrays need you to do the stuff yourself. Use lists if you find them better.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#3
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
list of object i think can be a strongly type and you the icomperable interface to determine which is lesser, if you understand why you have to overload operators this will make more sense