小编Hei*_*idi的帖子

while循环在C#中有多个条件

这是我的代码:

while( Func(x) != ERR_D)
{
   if(result == ERR_A) 
         throw...; 
   if(result == ERR_B)
         throw...;

  mydata.x = x;
 }
Run Code Online (Sandbox Code Playgroud)

问题是我想result = Func(x)在while条件中使用,因为结果将在while循环中检查.while循环应该调用Func(x)直到它返回ERR_D.我不能用

do{ 
    result = Func(x);
   if(result == ERR_A) 
         throw ...; 
   if(result == ERR_B)
         throw ...;
    mydata.x = x;
   }while(result != ERR_D); 
Run Code Online (Sandbox Code Playgroud)

在我的项目中,因为它第一次调用Func(x),这是我不想要的.但我试过while(result = Func(x) != ERR_D),它不起作用.任何解决这个问题的想法?

.net c# while-loop conditional-statements

5
推荐指数
2
解决办法
4972
查看次数

标签 统计

.net ×1

c# ×1

conditional-statements ×1

while-loop ×1