c# - CS0029:无法将类型“int”隐式转换为“bool”
问题描述
这是执行时 C# 中的一段代码,它给了我错误
错误:“无法将类型“int”隐式转换为“bool””
我无法理解我已将数组声明为boolean
变量,并且我的代码中没有其他int
变量,我的函数参数是否正确并不重要?
private static bool[,] array = new bool[41, 8];
public void SetArrayElement(int row, int col)
{
array[row, col] = 1;
}
解决方案
您声明了数组,bool
因此您不能分配integer
给它。您可以使用true
orfalse
代替。
private static bool[,] array = new bool[41, 8];
public void SetArrayElement(int row, int col)
{
array[row, col] = true; // assign either true or false.
}
推荐阅读
- c# - 映射到模型
- inno-setup - 显示使用 Inno Setup 在安装期间执行的操作列表
- jquery - 在 dataTable ajax 请求期间,隐藏的表单控件永远不会被初始化
- java - Spring REST 响应显示原始 Java 对象而不是 JSON 元素
- javascript - 如何模拟非异步方法以使用 Jest 引发异常?
- python - 列表包含 NULL 字节,CSV DictReader
- javascript - 无法使用reactjs从firebase获取对象数组
- solidity - Solidity 合约可以与特定的世界事件相关联吗?
- c++ - 如果 x > y,用 y 交换 x 的无分支版本?
- python - Python 3.7.2 32-Bit ZIP 密码破解器