怎么取出下面c#取出两个数组中相同的值 ?
string[] A= "朱雅君,姚怡尔,涂静";
string[] B= "姚怡尔,涂静,刘刚";
------解决方案--------------------------------------------------------
一个个循环对比 这是我的第一想法
------解决方案--------------------------------------------------------
var same=A.Intersect(B).ToArray();
------解决方案--------------------------------------------------------
http://jrunner.blog.51cto.com/1015356/655708
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- C# code
string[] A = new string[] { "朱雅君", "姚怡尔", "涂静" }; string[] B = new string[] { "姚怡尔", "涂静", "刘刚" }; var re = (from a in A select a).Intersect(from b in B select b).ToArray();
------解决方案--------------------------------------------------------
- C# code
string[] A = new string[]{"朱雅君","姚怡尔","涂静"}; string[] B = new string[]{"姚怡尔","涂静","刘刚"}; var vs = from s in A where B.Contains(s) select s; foreach (var v in vs) { MessageBox.Show(v.ToString()); }
------解决方案--------------------------------------------------------
linq就是好用。。简单又清晰
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
Linq非常方便。我给你们写个原始点的吧。。
- C# code
string[] A = {"朱雅君","姚怡尔","涂静"}; string[] B = {"姚怡尔","涂静","刘刚"}; foreach (var item in A) { foreach (var item2 in B) { if (item == item2) return item2; } }