c# - 如何比较字符串和 bool 数组?

标签 c#

我有如下两个数组:

_user string[3] containing "true" "true" and "true"
_test  bool[3] containing true true false

数组中的元素数量会因一次运行而异。我的问题是如何比较这两个数组中的值并在元素一对一匹配时返回 true。

希望有人能提供帮助,因为我的 C# 一点也不是很好。

珍妮特

最佳答案

使用bool.Parse将字符串转换为bool,使用SequenceEqual比较序列:

if (_user.Select(bool.Parse).SequenceEqual(_test))
{
    ...
}

关于c# - 如何比较字符串和 bool 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5756449/

相关文章:

C# 到 MusicXML?

c# - 在 Web API Controller 中接收 Json 反序列化对象作为字符串

c# - 以 C/C++ 作为后端的 WinForms 或 WPF 或 Qt for Windows GUI

c# - 新的 IntPtr.Add 方法 - 我是否错过了 int 的要点?

c# - 目录路径为字符串 : ensure DirectoryPathSeperator at the end of the string

c# - 使用 .Net 生成 SHA256 哈希的不同结果和 react native 库(相同输入)

c# - 如何按不同属性对 DataGrid 列进行排序

c# - 无法从 C# 将数据存储在 SQL Server 中

c# - 如何在表单例份验证重定向之前处理页面事件?

c# - 如何使用 XPath 获取 XML 节点的属性值