2
Answers

Array.Sort() and Sort()

Maha

Maha

11y
1.1k
1
When we sort an Array we use Array.Sort() and when we sort ArrayList we use Sort(). Please explain the reason. Example is given below.

eg:-

Employee[] empArray = new Employee[] { new Employee(333, 12.50), new Employee(111, 14.75), new Employee(222, 22.35) };

Array.Sort(empArray);

eg:-

ArrayList people = new ArrayList(); //this requires using System.Collections;

people.Add(new Person("John", "Doe", 84));
people.Add(new Person("Abby", "Normal", 25));
people.Add(new Person("Jane", "Doe", 76));

people.Sort();

Answers (2)