C# 如何检查数组列表中是否存在数组

原文:https://www.coder.work/article/2958674

列表:

一个数组列表,想检查一个确切的数组是否在列表中

cs 复制代码
List<int[]> Output = new List<int[]>();

有一个数组

cs 复制代码
int[] coordinates 

想检查coordinates 数组是否在Output 列表中?
最佳答案
使用SequenceEqual:

cs 复制代码
bool result = Output.Any(a => a.SequenceEqual(coordinates));

字典获取:

cs 复制代码
    Dictionary<int[], string[]> testDic = new Dictionary<int[], string[]>();
    int[] t = { 1, 2 };
    //找到key
    int[] key = testDic.Keys.Where(x => x.SequenceEqual(t)).FirstOrDefault();
    if (key != null)
    { 
        //对应的value
        string[] value_Instruction = testDic[key];
    }
相关推荐
大可不必了18 小时前
03 函数定义和调用
开发语言·python
I_belong_to_jesus18 小时前
C++关于分支预测的优化1
开发语言·c++·算法
承渊政道19 小时前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame
爱学习的程序媛19 小时前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
eggwyw20 小时前
Anaconda安装卸载的详细流程指南
开发语言·python
用户788477316341 天前
WinForms 迁移 WPF:Upgrade Assistant 覆盖 30%,剩下 70% 我手写了六周
c#
another heaven1 天前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
SomeOtherTime1 天前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain1 天前
C++转Java日记(10)
java·开发语言
总要学点什么1 天前
第105篇:三维特效-流动图片墙体效果——让箭头沿墙长滚,它俩竟是同一份代码
开发语言·javascript·ecmascript·gis·webgl·材质·cesium