在运行时,我收到以下错误
"对象必须实现IConvertible"
调用功能
lboxBuildingType.SelectedIndex = pharse.returning<int>xdoc.Root.Element("BuildingTypeIndex").Value);
public static T returning<T>(object o)
{
Tuple<bool, T, object> tmp;
switch (Type.GetTypeCode(typeof(T)))
{
////blah blah blah
case TypeCode.Int32:
tmp= (Tuple<bool,T,object>)Convert.ChangeType(I(o.ToString())), typeof(T)); // error
break;
////blah blah blah
}
}
private static Tuple<bool, Int32, Object> I(object o)
{
int i;
bool b;
Int32.TryParse(o.ToString(), out i);
b = (i == 0);
return new Tuple<bool, Int32, object>(b, i, o);
}
Run Code Online (Sandbox Code Playgroud)
码的目的是在通过<T>("15")并使其产生tuple<Bool,T,object>这将是tuple<true, 15, "15">
它出错了我用//错误标记的地方
c# ×1