从外部(C#)访问while循环内部的变量? [英] Access variable inside while loop from outside (C#)?

查看:52
本文介绍了从外部(C#)访问while循环内部的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我正试图从那一刻起达到MAX的价值,因此我可以在外面使用它,但我不能……任何人都有一些想法!!!在此先感谢

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); 

推荐答案

在启动while循环之前声明MAX.您拥有的方式只能在一段时间内访问.

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); 

这篇关于从外部(C#)访问while循环内部的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆