Tuesday, 17 September 2013

InvalidOperationException when using String.compare in foreach loop

InvalidOperationException when using String.compare in foreach loop

I simply want to compare a list of strings to a certain value. Here's my
code:
foreach (string s in myList)
{
int comp = String.Compare(s, line_to_delete);
if (comp == 0)
{
myList.Remove(s);
}
}
The thing is that whenever I use 'comp == 1' I get no exception, but I
want it to check if the strings are the same..

No comments:

Post a Comment