private static bool Add(string[] fields) { if (fields[0] != "add") { return(false); } if (fields.Length < 2) { return(false); } string name = fields[1] == null ? null : fields[1]; Measure qty = null; if (fields.Length > 2 && fields[2] != null) { double amt; if (!double.TryParse(fields[2], out amt)) { return(false); } string units = null; if (fields.Length > 3 && fields[3] != null) { units = fields[3]; } qty = new Measure(amt, units); } shoppingList.Add(name, qty); Console.Out.WriteLine($"Successfully added '{name}': {qty}."); return(true); }