Checking for null while converting to Dictionary

Need help in C# 5 replacing value with empty collection for the null ones

    

//Structure of the class Info
public class Info
{
     public IList<string> Type { get; set; }
     public IList<string> Flow { get; set; }
}

//Trying to convert the returned result into dictionary
db.InsertMissingInfo(result.Item1.ToDictionary(k => k.Key, v => new Info { Type = v.Value.Type, Flow = v.Value.Flow  }));

Open in new window


Here result.Item1 is Tuple which i am converting in to dictionary
How can i check if the v.Value.Flow is null here if it is null i want to put an empty collection
SriAsked:
Who is Participating?
 
käµfm³d 👽Commented:
You could use the coalesce operator:

db.InsertMissingInfo(result.Item1.ToDictionary(k => k.Key, v => new Info { Type = v.Value.Type, Flow = v.Value.Flow ?? new List<string>()  }));

Open in new window

0
 
SriAuthor Commented:
Able to check for null and fix the issue
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.