I would like to know how to write this in LINQ
You don't need LINQ for this; you can sort the existing list using a
Comparer<T>:
List<InterfaceB aselist = new List<InterfaceB ase>();
list.Sort((x, y) =>
{
int result = x.Ordering.Comp areTo(y.Orderin g);
if (result == 0) result = string.Compare( x.Title, y.Title);
return result;
});
or in C# 2 (VS2005):
list.Sort(deleg ate (InterfaceBase x, InterfaceBase y)
{
int result = x.Ordering.Comp areTo(y.Orderin g);
if (result == 0) result = string.Compare( x.Title, y.Title);
return result;
});
If you really want to use LINQ, you can - but note that you get a new
list - you don't sort the existing one:
List<InterfaceB asenewList = (
from item in list
orderby item.Ordering, item.Title
select item).ToList();
Marc
You don't need LINQ for this; you can sort the existing list using a
Comparer<T>:
List<InterfaceB aselist = new List<InterfaceB ase>();
list.Sort((x, y) =>
{
int result = x.Ordering.Comp areTo(y.Orderin g);
if (result == 0) result = string.Compare( x.Title, y.Title);
return result;
});
or in C# 2 (VS2005):
list.Sort(deleg ate (InterfaceBase x, InterfaceBase y)
{
int result = x.Ordering.Comp areTo(y.Orderin g);
if (result == 0) result = string.Compare( x.Title, y.Title);
return result;
});
If you really want to use LINQ, you can - but note that you get a new
list - you don't sort the existing one:
List<InterfaceB asenewList = (
from item in list
orderby item.Ordering, item.Title
select item).ToList();
Marc