tags:

views:

78

answers:

2

Hi guys,

   I have following code in VS2008
If Linq.Enumerable.Contains(Of String)(selectedUsersRoles, RoleCheckBox.Text) Then
                RoleCheckBox.Checked = True
            Else
                RoleCheckBox.Checked = False
            End If

I need the above code in VS2005

What can i do instead of linq in above code?Can anybody help?

+1  A: 
bool containsRole = false;
foreach(string entry in selectedUsersRoles)
{
  if(entry == RoleCheckBox.Text)
  {
    containsRole = true;
    break;
  }
}

RoleCheckBox.Checked = containsRole;

The code is C# but i guess u'll get the idea. This is for IEnumerable. If you have a list try Binary Worrier's sollution.

AZ
+1  A: 
RoleCheckBox.Checked = False
For Each str As String in selectedUsersRoles
     If str = RoleCheckBox.Text Then
          RoleCheckBox.Checked = True
          Exit For
     End If
Next

If you don't wish to alter the RoleCheckBox.Checked twice (when str is actually found) then declare a boolean flag (i.e. boolFound) with an initial False value, change it to true when found, and asign RoleCheckBox.Checked = boolFound after the "for each" loop....

Rodolfo G.