C# 类初始化错误

C# 类初始化错误,c#,xna,C#,Xna,我正在使用Visual Studio C#Express和Xna 4.0 好吧,我是一个业余程序员,我可能没有用最好的方法来做这件事,所以如果你想给我一个更好的方法来解决我的问题,那就太好了 我的问题是,当我运行这段代码时,我遇到了一个我不理解的错误 这是我正在使用的类,问题不在这里,但这很重要: class ShipType { public Vector2 Size; public int LogSlots; public int DefSlots; publ

我正在使用Visual Studio C#Express和Xna 4.0

好吧,我是一个业余程序员,我可能没有用最好的方法来做这件事,所以如果你想给我一个更好的方法来解决我的问题,那就太好了

我的问题是,当我运行这段代码时,我遇到了一个我不理解的错误

这是我正在使用的类,问题不在这里,但这很重要:

class ShipType
{
    public Vector2 Size;
    public int LogSlots;
    public int DefSlots;
    public int OffSlots;
    public int SpecSlots;

    public int HullBase;
    public int TechCapacity;
    public int EnergyCapacity;
    public int WeightBase;
    public string Class;
    public string Manufacturer;
    public string Description;

    public void Initialize(
        ref Vector2 Size,
        ref int LogSlots, ref int DefSlots, ref int OffSlots, 
        ref int SpecSlots, ref int HullBase, ref int TechCapacity, 
        ref int EnergyCapacity, ref int WeightBase,
        ref string Class, ref string Manufacturer, ref string Description)
    {

    }
}
这里是我遇到问题的地方,当运行Initialize方法时,我得到一个错误:

class AOSEngine
{
    public Player PlayerA = new Player();
    public List<ShipType> ShipTypeList = new List<ShipType>(10);

    public void Initialize()
    {
        //Build Ship Type List
        ShipTypeList = new List<ShipType>(10);
        ShipTypeList.Add(new ShipType());
        ShipTypeList[0].Initialize(new Vector2(0, 0), 4, 4, 4, 4, 
                                   100, 100, 100, 10, "Cruiser", 
                                   "SpeedLight", "");

    }
}
AOSEngine类
{
公共玩家PlayerA=新玩家();
公共列表ShipTypeList=新列表(10);
公共无效初始化()
{
//建造船型表
船型清单=新清单(10);
ShipTypeList.Add(新的ShipType());
发货类型列表[0]。初始化(新向量2(0,0),4,4,4,4,
100,100,100,10,“巡洋舰”,
"电子闪光",;
}
}
运行初始化行时发生如下错误:

最好的重载方法匹配
AOS.ShipType.Initialize(参考
Vector2 Size,…ref string Description)
具有一些无效参数


再一次,我可能做得不太好,因此如果您有任何更好的建议,我想听听。

由于您已将参数声明为
ref
,因此在传入变量时需要使用
ref
关键字:

ShipTypeList[0].Initialize(ref new Vector2(0, 0),ref 4,ref 4,ref 4,ref 4,ref 100,ref 100,ref 100,ref 10,ref "Cruiser",ref "SpeedLight",ref "");
也就是说,这里没有使用ref参数的好理由-最好从Initlialize()方法中删除
ref
关键字:


有关使用ref的原因和方法的详细信息,请参阅Jon Skeets的文章:

我感觉它可能很简单,但不幸的是,它似乎不起作用,我仍然会遇到同样的错误。我正确地使用了ref命令,对吗?只需对单词“ref”进行查找和替换,并将其完全删除:)好的,在这种情况下,我将删除ShipType类中initialize方法之前声明的所有变量,因为它们将在方法中声明,对吗?保持参数列表较小也是一个好主意(对于构造函数和方法)。大量的参数使得像这样的错误很难使用和调试。好的,谢谢你的帮助。我点击“这个评论对你很有帮助。”按钮对吗?这会给你很好的表现,对吗?
public void Initialize(
     Vector2 Size,
     int LogSlots,  int DefSlots,  int OffSlots,  int SpecSlots,
     int HullBase,  int TechCapacity,  int EnergyCapacity,  int WeightBase,
     string Class,  string Manufacturer,  string Description)
{
    this.LogSlots = LogSlots;
    this.DefSlots = DefSlots;
    //...etc...
}