January 24, 2012

Initialize values to string array

We can initialize the values to string array to null before assigning the values.
Use following code:



string[] users = null;
string[] roles = null;



for (int i = 0; i < RolesListBox.Items.Count; i++)

{
    //assing the length of array using this code
    roles = new string[RolesListBox.Items.Count]
    if (RolesListBox.Items[i].Selected == true)
     roles[i]= RolesListBox.SelectedItem.Text;
}


No comments:

Post a Comment