Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In the following little piece of code I get what appears to be a simple error at users in my for loop, but I don't see why. It is The name 'users' does not exist in the class or namespace. I get the error underline at user in the for loop. Obviously the IF(){} part is causing the problem but I don't see why this is a scope problem when dr[] = users[]; get assigned correctly.

 

Code:

if ( txtUserToImport.Text == "Travis" )

{

string[] users = {"1","Travis","M","Doe","System Architect","Dept","Admin"};

}

else if ( txtUserToImport.Text == "David" )

{

string[] users = {"2","David","L","Doe","Records Mngt Admin","ONPD","Admin"};

}

else

{

string[] users = {"3","John","H","Doe","Title","Dept","Guest"};

}

 

for (int i = 0; i < 7; i++)

{

dr = users;

}

Experience is something you don't get until just after the moment you needed it
  • Leaders
Posted

it's because you have " users " declared within the if statement, you need it declared outside it. eg:


string[] users; /// like this.

if ( txtUserToImport.Text == "Travis" )
{
users = {"1","Travis","M","Doe","System Architect","Dept","Admin"};
}
else if ( txtUserToImport.Text == "David" )
{
users = {"2","David","L","Doe","Records Mngt Admin","ONPD","Admin"};
}
else
{
users = {"3","John","H","Doe","Title","Dept","Guest"};
}

for (int i = 0; i < 7; i++) 
{
dr[i] = users[i];
}

Posted

Ahh, ok it's fixed. I just put this before my IF block

 

string[] users = new string[7];

 

and in my IF block I changed it to

 

users = new string[]{"1","foo","M","bar","blah","text","Admin"};

Experience is something you don't get until just after the moment you needed it

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...