I am trying to do union of three lists of type T in C# , but when any of them is null it throws null reference exception -
here code snippet:
var joinedlist = list1.list.where(x => x != null) .union(list2.list.where(x=> x!= null).union(list3.list.where(x => x!= null))).tolist();
var joinedlist = new list<t>(); if (list1.list != null) joinedlist = joinedlist.union(list1.list.where(x=>x!=null); if (list2.list != null) joinedlist = joinedlist.union(list2.list.where(x=>x!=null); if (list3.list != null) joinedlist = joinedlist.union(list3.list.where(x=>x!=null);
Comments
Post a Comment