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.
Try :
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).
Participant
858 Points
1472 Posts
check string in for loop...null
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.
Example:
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
}
Contributor
7386 Points
1981 Posts
Re: check string in for loop...null
Jul 21, 2014 11:57 AM|JohnLocke|LINK
That's the basics of checking for null. You could also check if a string was empty by using the WhiteSpace check
All-Star
48290 Points
18001 Posts
Re: check string in for loop...null
Jul 21, 2014 11:59 AM|PatriceSc|LINK
Hi,
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.
Try :
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).