Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

Access variable inside while loop from outside (C#)?

I'm New to C# and I'm trying to reach the value of MAX from the while so i can use it outside but i can't...anyone have some ideas !!! Thanks In Advance

while (Condition)
{    
    Double MAX = somecode.....
                         .....
}

Console.WriteLine("The OPTIMAL Value : " + MAX); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Declare MAX before you start the while loop. The way you have it you can only access within the while.

Double MAX = 0;
while (Condition)
            {    

                MAX = somecode.....
                                      .....
            }

            Console.WriteLine("The OPTIMAL Value : " + MAX); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...