Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#或javascript比较两个字符串数组_C#_Javascript_Asp.net_C# 4.0 - Fatal编程技术网

使用c#或javascript比较两个字符串数组

使用c#或javascript比较两个字符串数组,c#,javascript,asp.net,c#-4.0,C#,Javascript,Asp.net,C# 4.0,我有两个字符串数组名str_arr1[],str_arr2[]。具有相同或不同值的两个数组 str_arr1[] = { "one", "two", "three","four","Doctor","Engineer","Driver" }; str_arr2[] = { "one", "Doctor","Engineer" }; 通常str_arr1[]比str_arr2[]有更多记录。我想检查str_arr1[]是否有str_arr2[]。如果为真,则表示返回真。否则返回false。请使用

我有两个字符串数组名str_arr1[],str_arr2[]。具有相同或不同值的两个数组

str_arr1[] = { "one", "two", "three","four","Doctor","Engineer","Driver" };
str_arr2[] = { "one", "Doctor","Engineer" };
通常str_arr1[]比str_arr2[]有更多记录。我想检查str_arr1[]是否有str_arr2[]。如果为真,则表示返回真。否则返回false。

请使用此选项

static bool ArraysEqual<T>(T[] a1, T[] a2)
{
    if (ReferenceEquals(a1,a2))
        return true;

    if (a1 == null || a2 == null)
        return false;

    if (a1.Length != a2.Length)
        return false;

    EqualityComparer<T> comparer = EqualityComparer<T>.Default;
    for (int i = 0; i < a1.Length; i++)
    {
        if (!comparer.Equals(a1[i], a2[i])) return false;
    }
    return true;
}
static bool ArraysEqual(T[]a1,T[]a2)
{
if(参考值等于(a1,a2))
返回true;
如果(a1==null | | a2==null)
返回false;
如果(a1.长度!=a2.长度)
返回false;
EqualityComparer comparer=EqualityComparer.Default;
对于(int i=0;i
您没有清除这些条件。我将所有条件结合在一起

 string[] str_arr1 = new string[] { "one", "two", "three", "four", "Doctor", "Engineer", "Driver" };
 string[] str_arr2 = new string[] { "one", "aaaa", "yyy" };

 bool contains = !str_arr2.Except(str_arr1).Any(); // this will show true only if all the items of str_arr2 are in str_arr1 

 bool result = str_arr2.Any(x => !str_arr1.Contains(x));// this will show true if any of the items of str_arr2 are in str_arr1 
bool result=str_arr2.Any(x=>!str_arr1.Contains(x));
var str_arr1 = new string[] { "one", "two", "three", "four", "Doctor", "Engineer", "Driver" };
        var str_arr2 = new string[] { "one", "Doctor", "Engineer" };

        return str_arr1.Intersect(str_arr2).Count() == str_arr2.Length;
var inter = str_arr1.Intersect( str_arr2);

foreach (var s in inter)
{
    Console.WriteLine("present" + s); // or you can return somthin
}
function compareArrays(arr1, arr2) {
  if (arr1.length != arr2.length) {
    return false;
  }

  return arr1.sort().join() == arr2.sort().join();
}
var arr1 = ["one", "two", "three","four","Doctor","Engineer","Driver" ];
var arr2 = ["one", "Doctor","Engineer"];

    console.log(compareArrays(arr1,arr2));
 string[] str_arr1 = new string[] { "one", "two", "three", "four", "Doctor", "Engineer", "Driver" };
 string[] str_arr2 = new string[] { "one", "aaaa", "yyy" };

 bool contains = !str_arr2.Except(str_arr1).Any(); // this will show true only if all the items of str_arr2 are in str_arr1 

 bool result = str_arr2.Any(x => !str_arr1.Contains(x));// this will show true if any of the items of str_arr2 are in str_arr1