Adding an Element to an Array

Posted by coffeeaddict on Stack Overflow See other posts from Stack Overflow or by coffeeaddict
Published on 2010-04-02T18:51:46Z Indexed on 2010/04/02 19:23 UTC
Read the original article Hit count: 112

Filed under:

Ok, I cannot get this. I've looked at it and I don't see why it's out of bounds. I get the error at paypalItems[paypalItems.Length] = new PaymentDetailsItemType

PaymentDetailsItemType[] paypalItems = new PaymentDetailsItemType[order.OrderItems.Count];

for (int i = 0; i < order.OrderItems.Count; i++)
{

    paypalItems[i] = new PaymentDetailsItemType
    {
        Name = order.OrderItems[i].Name,
        Amount = ApiUtility.CreateBasicAmount(order.OrderItems[i].Price),
        Description = order.OrderItems[i].Name,
        Number = order.OrderItems[i].Sku,
    };
}

if (giftCardsTotal != 0)
{
    // add Coupons & Discounts line item
    paypalItems[paypalItems.Length] = new PaymentDetailsItemType
                                              {
                                                  Name = "Gift Cards",
                                                  Amount = ApiUtility.CreateBasicAmount(giftCardsTotal),
                                                  Description = "Gift Cards"
                                              };
}

© Stack Overflow or respective owner

Related posts about c#