|
using System;
using System.Collections.Generic;
using System.Text;
namespace GenericListSorting
{
class Program
{
static void Main(string[] args)
{
List<Employee> myEmployeeList = new List<Employee>();
myEmployeeList.Add(new Employee(81, "Anand", 25));
myEmployeeList.Add(new Employee(12, "Viral", 26));
myEmployeeList.Add(new Employee(31, "Meet", 20));
myEmployeeList.Add(new Employee(24, "Rahul", 28));
Console.WriteLine(Environment.NewLine + Environment.NewLine + "Default List:");
foreach (Employee p in myEmployeeList)
{
Console.WriteLine(p.ToString());
}
Console.WriteLine(Environment.NewLine + Environment.NewLine + "Sorted List(based on Id):");
myEmployeeList.Sort(Employee.IDComparison);
foreach (Employee p in myEmployeeList)
{
Console.WriteLine(p.ToString());
}
Console.WriteLine(Environment.NewLine + Environment.NewLine + "Sorted List(based on Name):");
myEmployeeList.Sort(Employee.NameComparison);
foreach (Employee p in myEmployeeList)
{
Console.WriteLine(p.ToString());
}
Console.WriteLine(Environment.NewLine + Environment.NewLine + "Sorted List (based on Age):");
myEmployeeList.Sort(Employee.AgeComparison);
foreach (Employee p in myEmployeeList)
{
Console.WriteLine(p.ToString());
}
Console.ReadKey();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Anand has been designing and developing applications using C# and the .NET framework since last 3 years.
When he's not writing code, you can catch him taking snaps or lost in playing computer games.