我有一个大致这样设计的课程:
class Vector3
{
float X;
float Y;
float Z;
public Vector3(float x, float y, float z)
{
this.X = x;
this.Y = y;
this.Z = z;
}
}
我有其他类将其实现为属性,例如:
class Entity
{
Vector3 Position { get; set; }
}
现在要设置实体的位置,我使用以下内容:
myEntity.Position = new Vector3(6, 0, 9);
我想通过为 Vector3 实现一个类似数组的初始化程序来为用户缩短这个时间:
myEntity.Position = { 6, 0, 9 };
但是,没有类可以继承数组。此外,我知道我可以通过一些小技巧来设法做到这一点:
myEntity.Position = new[] { 6, 0, 9 };
但这不是重点。:)
谢谢!