检查字符串的列表中存在字符串数组 [英] Check if string array exists in list of string

查看:121
本文介绍了检查字符串的列表中存在字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串数组列表。我提出一个新的字符串数组,通过迭代,并尝试把它放在里面的名单,但它不检查,看是否存在,当我使用包含函数,而是插入重复的。

 列表<字符串[]> possibleColumnValues​​ =新的List<字符串[]>();而(真){  字符串[] = RARR新的字符串[5];
  //一些code填充串放在这里  如果(!possibleColumnValues​​.Contains(RARR){
  {
      possibleColumnValues​​.Add(RARR);
  }
}


解决方案

 私有静态布尔AllElementInList(列表<字符串[]>列表,字符串[] ARR)
{
    返回list.Select(AR2 = GT; arr.All(ar2.Contains))。FirstOrDefault();
}

使用它作为:

 列表<字符串[]>名单=新名单,LT;字符串[]>();
        字符串[] ARR;        布尔标志= AllElementInList(列表,ARR);

I have a list of string arrays. I make a new string array through an iteration and try to put it inside the list, but it doesn't check to see if it exists when i use the contain function, and instead inserts duplicates.

List<string[]> possibleColumnValues = new List<string[]>();

while(true){

  string[] rArr = new string[5];
  //some code to populate the string goes here

  if (!possibleColumnValues.Contains(rArr){
  {
      possibleColumnValues.Add(rArr);
  }
}

解决方案

private static bool AllElementInList(List<string[]> list, string[] arr)
{
    return list.Select(ar2 => arr.All(ar2.Contains)).FirstOrDefault();
}

Use it as :

        List<string[]> list = new List<string[]>();
        string[] arr;

        bool flag = AllElementInList(list, arr);

这篇关于检查字符串的列表中存在字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆