travisowens Posted March 22, 2004 Posted March 22, 2004 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; } Quote Experience is something you don't get until just after the moment you needed it
Leaders dynamic_sysop Posted March 22, 2004 Leaders Posted March 22, 2004 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]; } Quote
travisowens Posted March 22, 2004 Author Posted March 22, 2004 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"}; Quote Experience is something you don't get until just after the moment you needed it
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.