0

my problem is the check of hole coordinates. I have a List<Hole> HoleList = new List<Hole>; This list has over 5000 listings with the under points (StartX-coordinate, StartY-coordinate, StartZ-coordinate, EndX-coordinate etc.). Now I start to search holes with the same Y-, X- & Z-coordinate but not the same name -> Part. But in the list can be up to 4 holes with the same coordinate. My question ist how can i mark or assign all holes with the same coordiantes so that i can find all pairs later in the list?

Here is my code:

 void StartAuswertung()
    {
        foreach (Hole B in HoleList)
        {
            foreach(Hole A in HoleList)
            {
                if (B.Equals(A))
                {
                    continue;
                }

            if ((B.StartX == A.EndeX &&
                B.StartY == A.EndeY &&
                B.StartZ == A.EndeZ) &&
                B.Part != A.Part)
                {
                    A.Pair_ST_EN.Add(B);
                    B.Pair_ST_EN.Add(A);
                }
            }
        }
    }

And this is my class:

public class Hole
{
    public string Name;
    public string Part;


    public double StartX;
    public double StartY;
    public double StartZ;

    public double EndeX;
    public double EndeY;
    public double EndeZ;

    public List<Hole> Pair_ST_EN = new List<Hole>();

}

Do you understand my problem?

Thanks for help!

  • possible duplicate of [How to find duplicate items in list<>?](http://stackoverflow.com/questions/15866780/how-to-find-duplicate-items-in-list) – O. R. Mapper Feb 24 '15 at 22:49
  • ... or of [this](http://stackoverflow.com/questions/4578260/how-to-find-all-duplicate-from-a-liststring), or [this](http://stackoverflow.com/questions/14363424/how-to-find-list-has-duplicate-values-in-liststring); also related: [this](http://stackoverflow.com/questions/454601/how-to-count-duplicates-in-list-with-linq), [this](http://stackoverflow.com/questions/3811464/how-to-get-duplicate-items-from-a-list-using-linq), and [this](http://stackoverflow.com/questions/18547354/c-sharp-linq-find-duplicates-in-list). – O. R. Mapper Feb 24 '15 at 22:51
  • 1
    He is not looking for exact duplicates @O.R.Mapper – Fatih BAKIR Feb 24 '15 at 22:52
  • @FatihBAKIR: True, though the linked problems seem close enough. It is just a matter of what one defines as a "duplicate"/as "equal". I think the solution from those linked questions should be given a try first; if there are any specific problems then, I'll be glad to vote to reopen the question (if it gets closed). – O. R. Mapper Feb 24 '15 at 23:02
  • 1
    [GroupBy](https://msdn.microsoft.com/en-us/library/vstudio/bb534334%28v=vs.100%29.aspx) with custom comparer will definitely find all duplicates, but it is not clear what OP wants to do with the duplicates... So question itself does not look duplicate to me, but likely unclear (definitely not yet worth to be pointing to "find duplicate items" questions)... – Alexei Levenkov Feb 24 '15 at 23:06
  • "so that i can find all pairs later in the list" -- this seems to be an important part of the question. I.e. finding the duplicates is one thing, but quickly retrieving them later is also needed. Correct? If so, it seems you may want to store the data in a dictionary, where the key is a `struct` containing the six coordinate values (x, y, z for start and end), and the value is a list of `Hole` objects. Depending on how you were using the original `List`, this dictionary may be able to replace it entirely. Please provide clarification, to affirm or not whether this is what you're asking. – Peter Duniho Feb 25 '15 at 00:28
  • Yes, the problem is that I need the duplicates later again! Because later in the process, i want to check the diameter of all holes with the same coordinate! – Northlight321 Feb 25 '15 at 07:26

0 Answers0