'Value cannot be null parameter name second
I have the following code. Here the newList is null because of which I am getting an error. How can I prevent this.
combinedList = (combinedList ?? new List<combinedList>()).Concat(newList).ToList();
Which is returning me the following error.
'Value cannot be null. Parameter name: second'
Solution 1:[1]
You could just use ?? again:
combinedList = (combinedList ?? new List<combinedList>())
.Concat(newList ?? new List<combinedList>())
.ToList();
Though it seems like you really just want this:
combinedList ??= new List<combinedList>();
if (newList != null)
{
combinedList.AddRange(newList);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DiplomacyNotWar |
