我有下面的代碼:一次幾個未分配的局部變量?
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