I have list with empty space("__")
List<string> MyList = (List<string>)Session["MyList "];
if(MyList !=null || MyList != "")
{
}
MyList != "" does not work if string has more space so
How can i check my list string is "" or null by using linq in c# ?
isEmpty() method of CollectionUtils can be used to check if a list is empty without worrying about null list. So null check is not required to be placed everywhere before checking the size of the list.
isEmpty(<string>) Checks if the <string> value is an empty string containing no characters or whitespace. Returns true if the string is null or empty.
Doing 'list[0] = null' only empties the 0th spot in that list instead of making that object be null, and i want the object to be set to null too. I expected that both A and B would make both of them null.
Now to check whether a list is empty or not, use the Count property. if (subjects. Count == 0) Console.
if(MyList!=null || MyList.All(x=>string.IsNullOrWhiteSpace(x)))
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With