Last post Jul 21, 2014 11:59 AM by PatriceSc
Jul 21, 2014 11:52 AM|slimbunny|LINK
How do I check the string in a for loop to see if it is null or not.
foreach (var item in validateList.ToString())
how do I check to see if item list is not null
if it is not null add to newList.Add(Item) --- only if not null
Jul 21, 2014 11:57 AM|JohnLocke|LINK
foreach (var item in validateList)
if (item != null)
That's the basics of checking for null. You could also check if a string was empty by using the WhiteSpace check
Jul 21, 2014 11:59 AM|PatriceSc|LINK
More likely the problem is that you are using var item in validateList.ToString() so more likely you iterate on each character of the type name of validateList.
foreach(var item in validateList)
The test itsef would be if (item!=null) or perhaps if(!String.IsNullOrEmpty(item)) depending on what you really want (ie only null or null or empty string).
When showing some code it's always best to tell exactly what is the behavior you see (here it seems the question you ask is not about the problem you really have if you tried somethjing and it didn't work more likely this is because item is a character rather
than a strring).