Helem Shoshi
Helem Shoshi

Reputation: 239

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);
                }

I'm using except the foreach and then write the coordinates that are not the same.

Both pixelscoordinatesinrectangle and newpixelscoordinates are List

Now what i want to do is instead writing to the text file(w) what is not the same to write only those are the same.

The same i mean in both Lists the variable s is identical.

Now for example if s is: X = 200 Y = 100 i know it's not the same coordinate in both Lists.

But now i want to change it so the variable s will contain only the variables that are identical in the both Lists.

For example if index 0 in one list contain same coordinates in index 0 in the other List then write this coordinate as the same.

But if one index that contain coordinates in one of the Lists is not the same coordinates in the other List then break stop the process.

I need to write in the end to the text file only if the whole Lists identical ! not only one index(item) but only if the whole Lists identical.

Upvotes: 1

Views: 52

Answers (1)

Kevin Brady
Kevin Brady

Reputation: 1724

the following code should find the items that exist in both lists

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);
            }

        }

Upvotes: 1

Related Questions