Your code does not make use of the ternary operator: you are using the "??" operator which evaluates an argument (a variable), and if the value is non-null, returns the evaluated value; if the value is null, then the value after the "??" is returned. Example:
string s1 = null;
string t1 = s1 ?? "whoop de doo";
string s2 = "hoop la";
string t2 = s2 ?? "yabba dabba doo"
You can use the ternary operator, referred to by Microsoft as the "conditional operator," which must
always return a value:
string t3 = (s1 != null) ? t2 : "shake, rattle, and roll";
With both ?? and ternary operators you are limited to one statement in each "segment," and you
must return something.
Clearly, your goal here is to remove an item from a collection. Keep in mind that .NET Collections Remove<T> operator returns a boolean value indicating the success or failure of a removal; you can use that return value, or ignore it. If you need to keep track of whether the removal was successful, try this:
bool itemIsRemoved = myCollection.Remove(myCollection.FirstOrDefault(p => p != null));
Here's a challenge:
List<string> lStr = new List<string> {null, string.Empty, "0", "1", "41", "2", "3", "4", "5" };
var itmIsRemoved1 = lStr.Remove(lStr.FirstOrDefault(str => str != null));
var itmIsRemoved2 = lStr.Remove(lStr.FirstOrDefault(str => str == "4"));
var itmIsRemoved3 = lStr.Remove(lStr.FirstOrDefault(str => str == string.Empty));
var itmIsRemoved4 = lStr.Remove(lStr.FirstOrDefault(str => str == null));
What do you think the value of 'itmIsRemoved, and the values in the List of strings, are after each line of the code above is executed ?