string id = (string)result.Rows[0]["Id"];
上面的代码行返回InvalidCastException。为什么会这样?
InvalidCastException
但是,如果我将代码更改为此, string id = result.Rows[0]["Id"].ToString(); 那么它就可以工作了。我在前一行代码中做错了什么吗?
string id = result.Rows[0]["Id"].ToString();
c# string casting
可能重复: 投射和转换有什么区别?
类型转换和类型转换之间的区别?如果你通过一个例子来做它会更好..
.net c#-4.0
.net ×1
c# ×1
c#-4.0 ×1
casting ×1
string ×1