string DaySuffix(int days)
{
string result;
if (days / 10 == 1)
result = "th";
else if (days % 10 == 1)
result = "st";
else if (days % 10 == 2)
result = "nd";
else if (days % 10 == 3)
result = "rd";
else
result = "th";
return result;
}
if语句的条件表达式必须是纯粹的bool型表达式。例如下面的诗句是错误的:
if (currentValue = 0) ...
c#要求所有的变量必须预先明确赋值后才能使用,因此,下列的程序是错误的:
int m;
if (inRange)
m = 42;
int copy = m; //错误,因为m可能不会被赋初值。
在C#中,if语句中不能包含变量声明语句,例如:
if (inRange)
int useless;// 错误
转载于:https://blog.51cto.com/5257890/915702