如何在循环中只显示一次消息框

Gm *_*sha 0 c# loops while-loop

我是New C in,

我正在使用messagebox来显示该行.但是它处于一个循环中,所以消息框显示的次数我想只显示一次,并且下次不应显示消息框.

try{
    using (var sr = File.OpenText("test.txt")){
        string newone = 20110501;//date
        string line;
        while ((line = sr.ReadLine()) != null){
            if (three => one){
                MessageBox.Show("Buy : " + line);
                //Its Displaying more than 50 times i want to displayit only
                //onetime and should dispose for the next Time
            }
        }
    }
} catch { }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

jav*_*iry 5

用这个:

try {
    using (var sr = File.OpenText("test.txt")) {
        bool flag = true;
        string newone = 20110501;//date
        string line;
        while ((line = sr.ReadLine()) != null) {
            if (flag) {
                MessageBox.Show("Buy : " + line);
                //Its Displaying more than 50 times i want to displayit only
                //onetime and should dispose for the next Time
            }
            flag = false;
        }
    }
} catch { }
Run Code Online (Sandbox Code Playgroud)