C#:向列表中添加必须包含坐标的数据

C#:向列表中添加必须包含坐标的数据,c#,.net,list,coordinates,C#,.net,List,Coordinates,我的问题是,我不知道如何将数据添加到列表中并保留坐标(我必须使用列表而不是数组) 下面是我应该通过保持坐标(I,j)向列表中添加数据的代码: for(int i=0;i

我的问题是,我不知道如何将数据添加到列表中并保留坐标(我必须使用列表而不是数组)

下面是我应该通过保持坐标(I,j)向列表中添加数据的代码:

for(int i=0;i
那我该怎么修呢


谢谢你的帮助

如果要在列表中存储多个值,在这种情况下,可以使用
元组

重新定义您的列表,如下所示:

//i, j, value
List<Tuple<int,int,int>> newLabyrinthList = new List<Tuple<int,int,int>>();
或者从一个循环

foreach(var tuple in newLabyrinth)
{
    int i = tuple.item1;
    int j = tuple.item2;
    int v = tuple.item3;
}
如果这不清楚,您可以定义要存储在列表中的类:

public class OperationAtCoordinate
{
    public int X {get;set;}
    public int Y {get;set;}
    public int Operation{get;set;}
}
然后,您需要一个如下列表:

List<OperationAtCoordinate> newnewLabyrinth = new List<OperationAtCoordinate>();

您需要在什么列表中添加内容?那数据就是坐标吗?你说的“保持我的坐标”是什么意思?如何保持?哪里为什么?如果
int迷宫
是您正在谈论的列表,那么您已经在做了。是的,但是我必须有类似于exp.array[I][j]=value的数组中的坐标。稍后在代码中,我需要访问它。你的意思是,你想在列表中存储坐标,即x和y吗<代码>列表
应该是
int迷宫
foreach(var tuple in newLabyrinth)
{
    int i = tuple.item1;
    int j = tuple.item2;
    int v = tuple.item3;
}
public class OperationAtCoordinate
{
    public int X {get;set;}
    public int Y {get;set;}
    public int Operation{get;set;}
}
List<OperationAtCoordinate> newnewLabyrinth = new List<OperationAtCoordinate>();
newnewLabyrinth.Add(new OperationAtCoordinate()
                    {
                       X = i,
                       Y = j,
                       Operation = //your value here
                    });