real newbie question on c#

  • Thread starter Thread starter Raymond Du
  • Start date Start date
R

Raymond Du

Hi,

//The following c# code:
for (int i = 0; i<args.Length;i++)
{
int var1 = SomeFunction();
if (args > var1)
break;
}
//Question: will i and var1 still be available outside the for loop, say
from here?

Thanks in Advance
 
Raymond Du said:
Hi,

//The following c# code:
for (int i = 0; i<args.Length;i++)
{
int var1 = SomeFunction();
if (args > var1)
break;
}
//Question: will i and var1 still be available outside the for loop, say
from here?


No, as I understand it. They are declared (created) in the for loop and
that is their scope.
 
No they will not be available outside the for loop. You would need to
create the variables outside the loop

int var = 0;
int i = 0;

for(i = 0; i<args.Length;i++))
{
var1 = SomeFunction();
if (args > var1)
break;
}

do something with var or i blah blah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top