I have some 3D data inside a list:
myDataList[0] - { X: 164 , Y: 79 , Z: 120 }
myDataList[1] - { X: 146 , Y: 63 , Z: 120 }
myDataList[2] - { X: 192 , Y: 59 , Z: 120 }
myDataList[3] - { X: 196 , Y: 59 , Z: 120 }
myDataList[4] - { X: 110 , Y: 55 , Z: 120 }
myDataList[5] - { X: 148 , Y: 69 , Z: 122 }
myDataList[6] - { X: 194 , Y: 59 , Z: 122 }
myDataList[7] - { X: 18 , Y: 47 , Z: 122 }
I want to get the X and Y coordinate based on the same Z coordinate
I am trying to do this in LINQ way with a loop.
for (int i = 0; i < myDataList.Count; i++)
{
myXList = myDataList.Where(x => myDataList[i].Z == myDataList[i + 1]).Select(x => x.X).ToList();
myYList = myDataList.Where(y => myDataList[i].Z == myDataList[i + 1]).Select(y => y.Y).ToList();
}
But my problem now is how to distinct the same Z from the list and select the X and Y. The above for
loop is wrong because it is only checking the the distinct Z for i
and i + 1
But not all the i at once.
Any helping hand?