Beispiel #1
0
        //The Main Function for this Class
        static void Main(string[] args)
        {
            ComparisionDeligateClass Sam = new ComparisionDeligateClass("Sameer", "NHES", 23);
            ComparisionDeligateClass Apu = new ComparisionDeligateClass("Apurv", "Loyala", 68);
            ComparisionDeligateClass Jay = new ComparisionDeligateClass("Jayaa", "Tagore", 18);

            ComparisionDeligateClass[] students = { Sam, Apu, Jay };

            //Displaying the ArrayList
            DisplayArray(students);

            //Sorting by the student name
            Array.Sort(students, ComparisionDeligateClass.compareByName);
            DisplayArray(students);

            //Sorting by the roll number
            Array.Sort(students, ComparisionDeligateClass.compareByRoll);
            DisplayArray(students);

            //Sorting the array by name + school
            Array.Sort(students, ComparisionDeligateClass.compareByNameAndSchool);
            DisplayArray(students);

            Console.ReadLine();
        }
Beispiel #2
0
 //For the roll number
 public static int compareByRoll(ComparisionDeligateClass obj1, ComparisionDeligateClass obj2)
 {
     return(obj1.Roll.CompareTo(obj2.Roll));
 }
Beispiel #3
0
 //For the combination of name and school
 public static int compareByNameAndSchool(ComparisionDeligateClass obj1, ComparisionDeligateClass obj2)
 {
     return(String.Compare(obj1.School + obj1.Name, obj2.School + obj2.Name));
 }