我有下面的代码:一次几个未分配的局部变量?
static void Main(string[] args)
{
byte currency;
decimal amount;
if (Byte.TryParse("string1", out currency) && Decimal.TryParse("string2", out amount))
{
Check(currency, amount);
}
Check(currency, amount); // error's here
}
static void Check(byte b, decimal d) { }
,并得到一个错误:
Use of unassigned local variable 'amount'
为什么我会得到它在所有,这是合法的,为什么只为amount
?为什么currency
在这种情况下分配和amount
- 不是?
请参阅此问题的其他信息:http://stackoverflow.com/questions/1542824/c-initialization-of-instance-fields-vs-local-variables – M4N 2010-02-18 22:59:46