Sunday, May 15, 2011

?? Operator used in Linq

Here is the Msdn link for ?? Operator

if need to order by a query which need to orderby column1 if not null, if null orderby column2

void Main()

List orderList= new List()
new Order(1, 4),
new Order(null,6),
new Order(2,5),
new Order(null,3),

var k = from p in
orderby p.ID ?? p.Count
select p;

class Order
public int? ID{get;set;}
public int? Count{get;set;}

public Order(int? id,int? count)
ID =id;
Count =count;

No comments:

Post a Comment