我有这门课
public class Line
{
public string ConnectionsIndex{get;set;}
}
我的 Linq 问题是我必须汇总这些行
var l1 = new Line{ ConnectionsIndex="01,02"};
var l2 = new Line{ ConnectionsIndex="02,03"};
var l3 = new Line{ ConnectionsIndex="01,03"};
进入这个
var l4 = new Line{ ConnectionsIndex="01,02,03"};
有可能与Linq有关吗?
细节:
当我添加我收藏中的其他物品时,事情变得更加复杂(至少对我而言)。
var l5 = new Line (ConnectionsIndex = "02,04");
var l6 = new Line (ConnectionsIndex = "03,06");
因为不存在与 03,04 , 01,04 , 01,06 和 02,06 对的其他行
不知道我解释的好不好...
在实践中,假设您拥有多边形的所有点,我想通过给出每个多边形的所有点之间的连接列表来从查询中获取所有项目的一行。
(我的列表包含多个多边形)
如果没有连接到所有其他点,则不应将一个点包含在结果中。
这是我的列表内容的示例:
ConnectionsIndex="166,171"
ConnectionsIndex="166,174"
ConnectionsIndex="166,333"
ConnectionsIndex="169,170"
ConnectionsIndex="171,175"
ConnectionsIndex="171,334"
ConnectionsIndex="167,174"
ConnectionsIndex="172,174"
ConnectionsIndex="174,335"
ConnectionsIndex="177,341"
ConnectionsIndex="180,200"
ConnectionsIndex="181,183"
ConnectionsIndex="182,199"
ConnectionsIndex="184,185"
ConnectionsIndex="186,188"
ConnectionsIndex="189,192"
ConnectionsIndex="190,230"
ConnectionsIndex="191,375"
例如,在此列表中,您有一个介于 166、171 和 334 之间的三角形
更多详情:
var group = lines.Where(x => x.ConnectionsIndex.Split(',').Contains(line.ConnectionsIndex.Split(',')[0]) || x.ConnectionsIndex.Split(',')。包含(line.ConnectionsIndex.Split(',')[1])).ToList(); if (group.Count()==1) { straight_lines.Add(line); } else { //这里我有一个“组”,所有点之间的线..我想得到不同的点 }