jazpearson
in reply to: Anonymous

Your baseDim variable is only checking the value of your itm object, and not each item in your lstStraight list.

 

Your baseDim2 object will be null, which is causing your programme to crash and is because itm.Dimensions does not contain a dimension with the exact name of "Width". 

 

If you want to check every "Length" dimension of the items in you lstStraight, then you should do something like:

foreach (Item value in lstStraight)
{
// this line is trying to get the Length dim for the current element in the list var baseDim = value.Dimensions.FirstOrDefault(x => x.Name == "Length");      if (baseDim == null) {
// the length dim doesn't exist in this item MessageBox.Show("Length dim does not exist"); } else {
// length dim exists - show it
MessageBox.Show(baseDim.Name + ": " + baseDim.Value.ToString()); }      }


and you can do similarly for your width dim.
You should be able to debug your object and see what dimensions on the items actually exist.....