Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
int? count = (from cartItems in storeDB.Carts
                     where cartItems.CartId == ShoppingCartId
                     select (int?)cartItems.Count).Sum();


and

C#
return count ?? 0;
Posted
Comments
KiranBabu M 12-Jan-12 6:07am    
what do u want to know in the above code?

1 solution

int? indicates a nullable integer i.e an integer type that can also store a null value.

the ?? is called the null-coalescing operator and is used for defining a default value for nullable types. So in your case if count is null, it will return 0.

Hope this helps
 
Share this answer
 
Comments
RaisKazi 12-Jan-12 6:06am    
My 5.
Wayne Gaylard 12-Jan-12 6:11am    
Thanks!
Yousif Mazeh 12-Jan-12 6:09am    
thank u very much :)
Wayne Gaylard 12-Jan-12 6:12am    
My pleasure - glad to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900