-6
我有具有動態參數並返回一個動態結果的方法。我希望能夠將null,int,string等傳入我的方法。但是,在所有情況下,我都會得到「NotSupportedException」。C#檢查動態值對空
MyMethod(null); // Causes problems (Should resolve to ref type?)
MyMethod(0); // Causes problems (Should resolve to int type)
public dynamic MyMethod(dynamic b)
{
if (value != null) {...}// Throws NotSupportedExpception
if (value != 0) {...} // Throws NotSupportedExpception
}
爲什麼要使用動態? – Joe
什麼是「價值」,爲什麼「b」不被使用?這段代碼很混亂。 –
你的方法似乎爲我工作的罰款(後我改名'B'到'value')。什麼是異常的調用堆棧? – svick