private static int SortTestObj2Compare(TestSortClass obj1, TestSortClass obj2)
{
int res = 0;
if ((obj1 == null) && (obj2 == null))
{
return 0;
}
else if ((obj1 != null) && (obj2 == null))
{
return 1;
}
else if ((obj1 == null) && (obj2 != null))
{
return -1;
}
if (obj1.ID > obj2.ID)
{
res = -1;
}
else if (obj1.ID < obj2.ID)
{
res = 1;
}
return res;
}
class TestSortClass
{
public int ID;
public string Name;
}
{
int res = 0;
if ((obj1 == null) && (obj2 == null))
{
return 0;
}
else if ((obj1 != null) && (obj2 == null))
{
return 1;
}
else if ((obj1 == null) && (obj2 != null))
{
return -1;
}
if (obj1.ID > obj2.ID)
{
res = -1;
}
else if (obj1.ID < obj2.ID)
{
res = 1;
}
return res;
}
class TestSortClass
{
public int ID;
public string Name;
}
List<TestSortClass> list=new List<TestSortClass>();
list.Sort(SortTestObj2Compare);//排序完成