c# - Merge two IEnumerables in elegant way -


i have 2 ienumerable variables, both can null. need merge them single list. here direct approach.

var ienumerable1 = getenumerable1();  var ienumerable2 = getenumerable2();   if(ienumerable1 != null){    if(ienumerable2 != null){       return ienumerable1.union(ienumerable2);    }    return ienumerable1; } else{    return ienumerable2; } 

is there more elegant way in less lines of code this?

just check null , assign enumerable.empty if null. can done in 1 step null coalescing operator ??

var ienumerable1 = getenumerable1() ?? enumerable.empty<whatevertype>(); var ienumerable2 = getenumerable2() ?? enumerable.empty<whatevertype>();   return ienumerable1.union(ienumerable2); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -