将列表中的每个元素与每个其他元素进行比较 [英] Comparing every element in a list against every other element
本文介绍了将列表中的每个元素与每个其他元素进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取列表中的每个元素并对其执行某些操作的最有效方法是什么。例如,假设您有一个包含x,y数据点的对象列表。你有一个可以计算点积的函数,但我想计算每个其他元素的点积
What is the most efficient way to take every element in a list and do some operation on it. For example say you have a list of objects that all have x,y data points. You have a function that can calculate the dot product but I want to calculate the dot product against every other element
推荐答案
嵌套循环。但是,你有什么期待奇迹?没有奇迹这样的东西。
-SA
Nested loop. But what, did you expect some miracle? There is no such thing as miracle.
—SA
string [] textlist = new string [] {a,b,c};
var intersecting = from text a in textlist
from string b in textlist
where((a!= b)&&(a.CompareTo(b)== -1))//&& a.SomeCondition(b)
选择新{object1 = a,object2 = b}
;
intersecting.Dump(结果);
Kishor Makwana
软件工程师
Insight Softech
www.insightsoftech.com
string[] textlist = new string[] {"a", "b", "c"};
var intersecting = from string a in textlist
from string b in textlist
where ((a != b) && (a.CompareTo(b) == -1)) // && a.SomeCondition(b)
select new { object1 = a, object2 = b }
;
intersecting.Dump("Result");
Kishor Makwana
Software Engineer
Insight Softech
www.insightsoftech.com
这篇关于将列表中的每个元素与每个其他元素进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文