Asl*_*fry 2 c# string casting
string id = (string)result.Rows[0]["Id"];
上面的代码行返回InvalidCastException。为什么会这样?
InvalidCastException
但是,如果我将代码更改为此, string id = result.Rows[0]["Id"].ToString(); 那么它就可以工作了。我在前一行代码中做错了什么吗?
string id = result.Rows[0]["Id"].ToString();
fub*_*ubo 5
它不起作用,因为ID有不同的类型。它不是string- 所以你可以转换它但不能投射它。
ID
string
归档时间:
10 年,5 月 前
查看次数:
856 次
最近记录: