Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check list string is null or empty [duplicate]

Tags:

c#

list

null

linq

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# ?

like image 586
user2869820 Avatar asked Oct 13 '13 11:10

user2869820


People also ask

How do you check if a list is null or empty?

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.

Does string isEmpty check for NULL?

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.

How do you make a list null in C#?

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.

How do you check whether the list is empty or not in C#?

Now to check whether a list is empty or not, use the Count property. if (subjects. Count == 0) Console.


1 Answers

if(MyList!=null || MyList.All(x=>string.IsNullOrWhiteSpace(x)))
{

}
like image 153
Damith Avatar answered Sep 27 '22 19:09

Damith