对于标题,我将在此放置一个我想要完成的例子:
namespace mdclass
{
class pClass
{
static void Main()
{
tiles<int> tl = new tiles<int>();
tl[0].X = 0;
}
}
class tiles<T> : List<T>
{
public int X
{
//get/set the X-coordonate
}
public int Y
{
//get/set the Y-coordonate
}
}
}
如何从[0]
中的tl[0]
转移public int X
并使用它?
答案 0 :(得分:3)
为x和y坐标创建一个类:
public sealed class Point {
public int X { get; set; }
public int Y { get; set; }
}
使用Point
类将坐标存储到列表中:
public sealed class Program {
public static void Main() {
var tiles = new List<Point>();
tiles.Add(new Point { X = 5, Y = 10 });
tiles[0].X = 15;
}
}
答案 1 :(得分:0)
你能不能公开吗?
然后myInt = mypClass.tl[0].X
答案 2 :(得分:0)
这样的数据层次结构可能适合您(没时间添加实际代码,抱歉!)。然后你可以实现适当的getter和setter。
Public class Grid {
List<Row>
}
Public class Row{
List<Point>
}
Public Class Point{
public int X { get; set; }
public int Y { get; set; }
}