Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have the following code:

C#
public void Sort()
{

    Collection = (from pricing in Collection orderby pricing.Prices.Price select pricing).ToList();

}


The problem is I get a null reference error when any of the values in the list is null.

It works just fine when all values are not null.

how do I overcome this error?

Thanks!
Posted
Comments
Tomas Takac 20-Feb-14 17:25pm    
What do you want to do with the null values? Exclude them? Or put the at the and of the list?
slayasty 20-Feb-14 17:29pm    
I want to exclude them out of the list

1 solution

You can exclude the null values like this:

C#
Collection = (
    from pricing in Collection 
    where pricing != null && pricing.Prices != null
    orderby pricing.Prices.Price 
    select pricing).ToList();
 
Share this answer
 
Comments
slayasty 20-Feb-14 17:42pm    
Thanks alot! :)

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