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); 回答1: 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); 回答2: You must