[英]How can I search a List for a partial match of variables inside its listed elements, then return one variable from a found match?
我有一个自定义列表,其中包含每个包含3个整数变量(x,y,height)的自定义类。 我希望能够在列出的元素中搜索与“ x,y”都匹配的任何元素,然后在我不知道当前是什么“高度”(仅当前x / y)的情况下返回“高度”。
这是自定义类
public class ConstructionCoordinates
public int x;
public int y;
public int height;
public ConstructionCoordinates(int xCoord, int yCoord, int levelHeight)
{
x = xCoord;
y = yCoord;
height = levelHeight;
}
这是自定义列表
public List<ConstructionCoordinates> constructionCoordList = new List<ConstructionCoordinates>();
foreach (ConstructionCoordinates constructionCoord in constructionCoordList) {
if (constructionCoord.x == x && constructionCoord.y == y) {
// Place your logic here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.