using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
public class comstude : IComparer<student>
{
public int Compare(student x, student y)
{
return x.avrage.CompareTo(y.avrage);
}
}
public class student
{
public string name;
public double avrage;
public student(string name1, double av)
{
this.name = name1;
this.avrage = av;
}
public static List<student> getstudentlist()
{
List<student> templist = new List<student>();
templist.Add(new student("esa", 10));
templist.Add(new student("reza", 20));
templist.Add(new student("reza1", 17.50));
templist.Add(new student("reza2", 16));
templist.Add(new student("reza3", 19));
templist.Add(new student("reza4", 7));
return templist;
}
public override string ToString()
{
return string.Format("name is : {0}\t and averg is\t {1}", name, avrage);
}
}
class Program
{
static void Main(string[] args)
{
List<student> list = student.getstudentlist();
list.Sort(new comstude());
foreach (student var in list)
{
Console.WriteLine(var);
}
Console.ReadKey();
}
}
}This code snippet is for implement IComparer interface, you can sort your class object in simple way.