判断两个数组是否相同

#region Test用的

static void Write列名Dic()

{

StreamWriter SW = new StreamWriter(MDIParent1.Root + @"列名Dic.txt", true, Encoding.UTF8);

foreach (var item in 列头Dic)

{

string 数据Line = item.Key + "=" + item.Value + ",";

SW.WriteLine(数据Line);

}

SW.Close();

}

public static void Add空列()

{

// 初始One列Dic();

// Write列名Dic();

}

public static string 判断两个数组是否相同()

{

string[] a = { "a", "a1", "b", "b1" };

string[] b = { "b", "b1", "a", "a1" };

int i = 0;

foreach (string sa in a)

{

foreach (string sb in b)

{

if (sa == sb) i++;

}

}

string result = (i <a.Length || a.Length != b.Length)

?"不同":"相同";

string[] arr2 = new[] { "1", "2", "3", "4", "5" };

string[] arr1 = new[] { "1", "3", "5" };

var sameArr = arr1.Intersect(arr2).ToArray();

//找出相同元素(即交集)

var diffArr = arr1.Where(c => !arr2.Contains(c)).ToArray();

//找出不同的元素(即交集的补集)

return result;

}

#endregion 列名Dic

(0)

相关推荐