我将你的代码封装到了一个名为Test
的方法中,并通过循环不同大小(size
)的值来调用它:
using System;
public class Program
{
public static void Main()
{
for(int i = 35; i<=45; i++)
{
Test(i);
}
}
static void Test(int size)
{
Console.Write("Test with {0}:", size);
string color = "black";
if (size == 40 && (color == "black" || color == "blue"))
{
Console.WriteLine("ok, i'm gonna take it");
}
else if (size <= 38 )
{
Console.WriteLine("it's a little too small but i'm gonna take it anyways");
}
else if(size >= 40)
{
Console.WriteLine("it's a little too big but i'm gonna take it anyways");
}
else if ((color != "black" || color != "blue") && (size <= 38 || size >= 40))
{
Console.WriteLine("the size is fine but i would prefer another color");
}
else
{
Console.WriteLine();
}
}
}
得到的结果如下:
Test with 35: it's a little too small but i'm gonna take it anyways
Test with 36: it's a little too small but i'm gonna take it anyways
Test with 37: it's a little too small but i'm gonna take it anyways
Test with 38: it's a little too small but i'm gonna take it anyways
Test with 39:
Test with 40: ok, i'm gonna take it
Test with 41: it's a little too big but i'm gonna take it anyways
Test with 42: it's a little too big but i'm gonna take it anyways
Test with 43: it's a little too big but i'm gonna take it anyways
Test with 44: it's a little too big but i'm gonna take it anyways
Test with 45: it's a little too big but i'm gonna take it anyways
我不是很明白为什么你似乎提到当选择非39的尺码时没有输出。在我看来,情况似乎恰恰相反。