Skip to main content
 首页 » 编程设计

c#之Bool 到 C# 中的字符串

2024年02月13日26xiaohuochai

我运行的 C# 应用程序很大,所以我只包含了一部分代码

我的代码:

allowGift = Convert.ToInt32(dRow[14]) == 1; 
allowInventoryStack = Convert.ToInt32(dRow[15]) == 1; 
interactionType = InterractionTypes.GetTypeFromString((string)dRow[16]); //Line of error 

以及堆栈跟踪的错误

System.InvalidCastException: Unable to cast object of typpe 'System.Boolean' to type 'System.String'

请您参考如下方法:

取而代之的是:

(string)dRow[16] 

尝试ToString:

dRow[16].ToString() 

或者Convert.ToString :

Convert.ToString(dRow[16])