I am doing some shipping calculations. I need some help trying to figure this out.
Basically, I have a generic list of products with Length, Width, and Height properties.
I would like to EASILY look at the products and find the largest values of all three properties.
From here, I can do some math and figure out the box size based on the # of products.
My initial thought would be to make 3 arrays and find the max of each. Just wanted to see if there was a simpler or cooler way I didnt’ know.
Sounds like an array of arrays. As you read each element (box) from your data source (SQL Server, XML, etc), create an 3-member array and insert the attributes in order of size. Then, add the three-member array to an array of arrays. You can then sort the array of arrays by the first, second or third member using LINQ or some other function.
Becomes:
or
or
Then, you can sort the array by the first element, second element, etc.
You could easily build an array of arrays in a single statement using LINQ, but exactly how you would do so depends on the data source. Assuming you have an class named
Boxwith three parameters,Length,WidthandHeight, and that you have created a strongly-typed collection containing instances of this class: