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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -