用C#来串吗?
我运行的C#应用程序很大,所以只包含了部分代码 我的代码:用C#来串吗?,c#,string,boolean,C#,String,Boolean,我运行的C#应用程序很大,所以只包含了部分代码 我的代码: allowGift = Convert.ToInt32(dRow[14]) == 1; allowInventoryStack = Convert.ToInt32(dRow[15]) == 1; interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error 以及堆栈跟踪的错误 System.InvalidCastExce
allowGift = Convert.ToInt32(dRow[14]) == 1;
allowInventoryStack = Convert.ToInt32(dRow[15]) == 1;
interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error
以及堆栈跟踪的错误
System.InvalidCastException:无法将类型为“System.Boolean”的对象强制转换为类型为“System.String”
与此相反:
(string)dRow[16]
尝试ToString
:
dRow[16].ToString()
或转换.ToString
:
Convert.ToString(dRow[16])
与此相反:
(string)dRow[16]
尝试ToString
:
dRow[16].ToString()
或转换.ToString
:
Convert.ToString(dRow[16])
更改此行:
interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error
为此:
interactionType = InterractionTypes.GetTypeFromString(dRow[16].ToString()); //Line of error
更改此行:
interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error
为此:
interactionType = InterractionTypes.GetTypeFromString(dRow[16].ToString()); //Line of error
使用
dRow[16]代替(string)dRow[16]
使用dRow[16]。ToString()
代替(string)dRow[16]
使用dRow[16]。ToString()
Abool
不能直接转换为字符串,它需要转换。您只需使用转换器
类,就像您在代码中的其他地方所做的那样
InterractionTypes.GetTypeFromString(Convert.ToString(dRow[16]));
bool
不能直接转换为需要转换的字符串。您只需使用转换器
类,就像您在代码中的其他地方所做的那样
InterractionTypes.GetTypeFromString(Convert.ToString(dRow[16]));
dRow
的类型是什么?什么是交互类型?什么线路导致了错误?您似乎正在使用。虽然下面的大多数答案都是善意的,但它们不会起作用,因为InteractionType
没有从True
或False
转换而来。很抱歉,根据您提供给我们的信息,您的问题无法回答。请查看InteractionType
enum(其中包括“football”、“teleport”和“firegate”等值),并确保传递给GetTypeFromString
的值都在其中。dRow
的类型是什么?什么是交互类型?什么线路导致了错误?您似乎正在使用。虽然下面的大多数答案都是善意的,但它们不会起作用,因为InteractionType
没有从True
或False
转换而来。很抱歉,根据您提供给我们的信息,您的问题无法回答。请查看InteractionType
enum(其中包括“football”、“teleport”和“firegate”等值),并确保传递给GetTypeFromString
的值在其中。解析代码中的未知交互类型:False System.InvalidCastException:指定的强制转换不是validUnkown解析代码中的交互类型:False System.InvalidCastException:指定的强制转换不是validUnkown解析代码中的交互类型:FalseSystem.InvalidCastException:指定的强制转换无效请查看@Michael Petrotta评论以了解您的问题。此错误与您的问题无关,您的问题是如何将布尔值转换为字符串。此错误是由于使用了您正在使用的interactionTypes
库,该库不接受False
作为有效输入值。解析代码中未知的交互类型:False System.InvalidCastException:指定的强制转换无效请查看@Michael Petrotta注释以了解您的问题。此错误与您的问题无关,您的问题是如何将布尔值转换为字符串。此错误是由于使用了您正在使用的interactiontypes
库,该库不接受False
作为有效输入值。