I have a class that is dealing with objects i have created for example;
StockItem2 = new CarEngine("Mazda B6T", 1252, 8025, 800, "Z4537298D");
//StockItem2 = new CarEngine("description", cost, invoice #, weight, engine #)
I also have a static int setting the last invoice number to 10,000.
internal static int LastStockNumber = 10000;
If no invoice number is entered, i want it to auto assign one and increment by 1 each time, so 10,001 / 10,002 etc..
CarEngine has 2 constructors, this is the one that is meant to assign the invoice number if one is not entered. It takes the description, cost, weight, engine number and should autoassign from 10,001 onward but it seems to be incrementing by 2-3 at a time, any ideas why?
public CarEngine(string Description, int CostPrice, int Weight, string EngineNumber)
: base(Description, CostPrice, Weight)
{
LastStockNumber++;
StockNumber = LastStockNumber;
this.CostPrice = CostPrice;
this.Description = Description;
this.Weight = Weight;
this.EngineNumber = EngineNumber;
}
// this is in the stockitem class //
public StockItem(string Description, int CostPrice)
{
LastStockNumber++;
StockNumber = LastStockNumber;
this.Description = Description;
this.CostPrice = CostPrice;
}
//this is in the heavystockitem class//
public HeavyStockItem(string Description, int CostPrice, int Weight) : base(Description, CostPrice)
{
StockNumber = LastStockNumber;
LastStockNumber++;
this.CostPrice = CostPrice;
this.Description = Description;
this.Weight = Weight;
}