I’m Using Visual Studio C# Express and Xna 4.0
Alright, I’m an amateur programmer and I’m probably not doing this the best way, so If you would like to show me a better way and fix my problem that would be great.
My problem is I’m getting an error I do not understand when I run this code.
This is the class I’m using, the problem isn’t here but this is important:
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)
{
}
}
Here is where I get the problem, When running the Initialize Method I get an error:
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", "");
}
}
The error occurs when running the Initialize Line and is as follows:
The Best Overloaded Method Match for
AOS.ShipType.Initialize(refhas some invalid arguments.
Vector2 Size, ... ref string Description)
Once again, I probably didn’t do this very well, so if you have any suggestions for doing it better I would like to hear it.
Since you have declared your parameters as
ref, you need to use therefkeyword when you pass in the variables:That said, there is no good reason to use ref parameters here – you’re better off removing the
refkeyword from the Initlialize() method:For detail about why and how to use ref, see Jon Skeets article: http://www.yoda.arachsys.com/csharp/parameters.html