Hello to C# experts,
I need help with this compliation error:
Cannot apply indexing with [] to an expression of type 'object'
else
{
try
{
OrderItem drinkOrder = new OrderItem("","",0,0.0m); // Referencing from a class within a package.
drinkOrder[itemCountInteger].quantityInteger
= int.Parse(quantityTextBox.Text);
if (drinkOrder[itemCountInteger].quantityInteger != 0)
{
drinkOrder[itemCountInteger].drinkString
= drinkTypeComboBox.SelectedItem.ToString();
drinkOrder[itemCountInteger].priceDecimal
= itemPriceDecimal;
totalOrderDecimal += itemPriceDecimal
* drinkOrder[itemCountInteger].quantityInteger;
drinkTotalInteger += drinkOrder[itemCountInteger]
.quantityInteger;
clearForNextItem();
orderCompleteButton.Enabled = true;
itemCountInteger++;
}
________________________________________________________________
those i highlighted in blue are those with the blue swiggly after i place in the code for referencing those variable from a class.
My tutor told the class to try it as a challenge but after i got to this point i am stuck, not sure how to continue this.
So really need some help from C# experts to explain to me how to solve so i will be able to solve it easily in future.
Loading
meliPosted Jun 9, 2009, 1:14 PM
looking at your code, you did not create an array of the object yet you try to access it as it's an array of the object, that is the problem.
You should create an array of the object, initialize them before you can use it as you shown in your code.
OrderItem[] drinkOrder ....
Good luck