我知道哪些物品不一样,我怎么知道哪些物品相同?
I know what items are not the same how do i know what are the same?
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> differenceQuery =
pixelscoordinatesinrectangle.Except(newpixelscoordinates);
// Execute the query.
foreach (Point s in differenceQuery)
w.WriteLine("The following points are not the same" + s);
}
我用的除了foreach然后写的坐标不一样
pixelcoordinatesinrectangle和newpixelscoordinates都是List
现在我想做的是写入文本文件(w) 不一样的东西只写那些是一样的。
我的意思是在两个列表中变量 s 是相同的。
现在例如如果 s 是:X = 200 Y = 100 我知道它在两个列表中的坐标不同。
但现在我想更改它,使变量 s 将仅包含两个列表中相同的变量。
例如,如果一个列表中的索引 0 在另一个列表中的索引 0 中包含相同的坐标,则将此坐标写为相同。
但是如果一个索引包含一个列表中的坐标与另一个列表中的坐标不同,则中断停止该过程。
只有当整个列表相同时,我才需要最后写入文本文件!不仅是一个索引(项目),而且只有在整个列表相同的情况下。
以下代码应该找到两个列表中都存在的项目
static void Main(string[] args)
{
var pixelscoordinatesinrectangle = new List<Point>() { new Point(200, 100), new Point(100, 100), new Point(200, 200) };
var newpixelscoordinates = new List<Point>() { new Point(200, 100), new Point(400, 400) };
FindMatchingPoints(pixelscoordinatesinrectangle, newpixelscoordinates);
Console.ReadKey();
}
private static void FindMatchingPoints(List<Point> pixelscoordinatesinrectangle, List<Point> newpixelscoordinates)
{
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> matchingPoints = pixelscoordinatesinrectangle.Where(p => newpixelscoordinates.Contains(p));
// Execute the query.
foreach (Point s in matchingPoints)
Console.WriteLine("The following points are the same" + s);
}
}
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> differenceQuery =
pixelscoordinatesinrectangle.Except(newpixelscoordinates);
// Execute the query.
foreach (Point s in differenceQuery)
w.WriteLine("The following points are not the same" + s);
}
我用的除了foreach然后写的坐标不一样
pixelcoordinatesinrectangle和newpixelscoordinates都是List
现在我想做的是写入文本文件(w) 不一样的东西只写那些是一样的。
我的意思是在两个列表中变量 s 是相同的。
现在例如如果 s 是:X = 200 Y = 100 我知道它在两个列表中的坐标不同。
但现在我想更改它,使变量 s 将仅包含两个列表中相同的变量。
例如,如果一个列表中的索引 0 在另一个列表中的索引 0 中包含相同的坐标,则将此坐标写为相同。
但是如果一个索引包含一个列表中的坐标与另一个列表中的坐标不同,则中断停止该过程。
只有当整个列表相同时,我才需要最后写入文本文件!不仅是一个索引(项目),而且只有在整个列表相同的情况下。
以下代码应该找到两个列表中都存在的项目
static void Main(string[] args)
{
var pixelscoordinatesinrectangle = new List<Point>() { new Point(200, 100), new Point(100, 100), new Point(200, 200) };
var newpixelscoordinates = new List<Point>() { new Point(200, 100), new Point(400, 400) };
FindMatchingPoints(pixelscoordinatesinrectangle, newpixelscoordinates);
Console.ReadKey();
}
private static void FindMatchingPoints(List<Point> pixelscoordinatesinrectangle, List<Point> newpixelscoordinates)
{
if (pixelscoordinatesinrectangle != null && newpixelscoordinates != null)
{
IEnumerable<Point> matchingPoints = pixelscoordinatesinrectangle.Where(p => newpixelscoordinates.Contains(p));
// Execute the query.
foreach (Point s in matchingPoints)
Console.WriteLine("The following points are the same" + s);
}
}