2016-07-25 12 views
0

2 ifステートメントの代わりに1ステートメントで2つのdouble値を解析するにはどうすればよいですか?1つのステートメントで2つのダブル値を解析する - C#

私のコード:もしブロックのみが入力されていることを

if (Double.TryParse(Console.ReadLine(), out a) 
    && Double.TryParse(Console.ReadLine(), out b)) 
{ 

} 
else 
{ 

    continue; 
} 

注:

double a, b; 
while (true) 
{ 
    if (Double.TryParse(Console.ReadLine(), out a)) 
    { 
    } 
    else 
    { 


     continue; 
    } 

    if (Double.TryParse(Console.ReadLine(), out b)) 
    { 

    } 
    else 
    { 

     continue; 
    } 
    break; 
} 

私はこのような

答えて

6

何かをすでにそれで検索しましたが、何か良い結果が見つかりませんでした両方の値が正常に解析された場合

+1

「else」と「continue」はここでは冗長です。 –

0

ifはここでは重複していますので、不要で、不要なコードでは読みにくくなりますcontinue

double a, b; 
while (!(double.TryParse(Console.ReadLine(), out a) && 
     double.TryParse(Console.ReadLine(), out b)) 
{ 
} 

//a and b successfully parsed. 
関連する問題