OLD
class Program
{
private static bool myMethod(int x)
{
if (x > 100)
{
return true;
}
else
{
return false;
}
}
static void Main(string[] args)
{
System.Diagnostics.Debug.WriteLine(myMethod(100));
System.Diagnostics.Debug.WriteLine(myMethod(101));
}
}
NEW
class Program
{
private static bool myMethod(int x){
return x > 100;
}
static void Main(string[] args)
{
System.Diagnostics.Debug.WriteLine(myMethod(100));
System.Diagnostics.Debug.WriteLine(myMethod(101));
}
}
Result
FalseTrue
・条件判断式はbool型でtrue, falseの値を持つ
なので結果をそのまま返却できる
引用元:
C#ショートプログラミング
0 件のコメント:
コメントを投稿