作为介绍,我正在创建一个基础的四叉树引擎,用于个人学习目的。我希望这个引擎能够处理许多不同类型的形状(目前我选择使用圆和正方形),所有形状都会在窗口中移动,并在发生碰撞时执行某些操作。
以下是我迄今为止拥有的形状对象:
现在我的问题是,如何在C#中创建一个通用列表(
我只知道这个问题有一个非常明显的答案,但无论如何,我都会感激任何帮助。我正在尝试重新学习C#; 显然已经有一段时间了...
以下是我迄今为止拥有的形状对象:
public class QShape {
public int x { get; set; }
public int y { get; set; }
public string colour { get; set; }
}
public class QCircle : QShape {
public int radius;
public QCircle(int theRadius, int theX, int theY, string theColour) {
this.radius = theRadius;
this.x = theX;
this.y = theY;
this.colour = theColour;
}
}
public class QSquare : QShape {
public int sideLength;
public QSquare(int theSideLength, int theX, int theY, string theColour) {
this.sideLength = theSideLength;
this.x = theX;
this.y = theY;
this.colour = theColour;
}
}
现在我的问题是,如何在C#中创建一个通用列表(
List<T> QObjectList = new List<T>();
),以便我可以拥有一个列表,其中包含所有这些可能具有不同属性的各种形状(例如,QCircle具有“半径”属性,而QSquare具有“边长”属性)? 最好提供实现示例。我只知道这个问题有一个非常明显的答案,但无论如何,我都会感激任何帮助。我正在尝试重新学习C#; 显然已经有一段时间了...