Because you have a space in
" 74". The two values are not equal because the second one
"74" without the space.
Trim on your values to remove whitespace:
string temp = ids[i].Trim(); string temp2 = raditem.Value.ToString().Trim();
Also, always use the .Equals overload for the
String class, as you can control the culture for the string comparison. In this case it doesn’t matter because they’re numerals but it could matter if you want to compare to alphabetical strings where you want “A” to equal “a” and so forth.
Furthermore, if you are sure your array contains only numbers, I could recommend converting the values to numbers before comparing them.
// one way to validate is wrap this in a try-catch and handle input format error. int temp = Convert.ToInt32(ids[i].Trim());
That way if you have a case where there aren’t numbers, you could validate and complain to the user or whatever you want.