If your ShipBoxes needs to contain a varying number of packages, here's what I would do:
1. Create a "Package" struct with all of the fields that you need to identify a package. It might look like this:
public struct Package { public int PieceNum; public float Weight; public bool COD; public float DVal; }
2. If your ShipBoxes has other properties in addition to the list of packages, go ahead and create it as a class. If you're in VS2005, your pakages property will be a generic list, declared like this: List<Package> Packages;. In VS2003, you'll have to use an ArrayList instead and cast each Package back and forth as an object.
3. If ShipBoxes contains ONLY packages, I wouldn't create a class, I just use either the generic list or the ArrayList instead.
To access each package, your code will look something like this:
Building the ShipBox list 2003 ArrayList ShipBox = new ArrayList(); Package pkg = new Package(); pkg.PieceNum = 1; ... - load package properties into pkg. ShipBox.Add((Object) pkg);
2005 List<Package> ShipBox = new List<Package>(); Package pkg = new Package(); pkg.PieceNum = 1; ...-load package properties into pkg. ShipBox.Add(pkg);
Walking through the ShipBox list - both versions of VS foreach (Package pkg in ShipBox) { //do whatever you need to do with it. }
-Dell
|