C# 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • merinodaniel
    New Member
    • May 2007
    • 5

    #1

    C# 2005

    hi all, first post so pls dont be hard with me :p
    well i have this code and i dont know why it says error pls check it :

    double total = 0.0;
    int size = _receipt.Count;
    for (int i = 0; i <= size; i++)
    {
    if ((Receipt)_rece ipt[i] is ItInvoices) //the ERROR is in this line
    {
    ItInvoices itinvoi = (ItInvoices)_re ceipt[i];
    total = total + itinvoi.getNeto ();
    }
    else
    {
    Ticket tick = (Ticket)_receip t[i];
    total = total + tick.getNeto();
    }
    Console.WriteLi ne(total);
    }


    the ERROR says: The index was outside the interval. It must be a nonnegative and inferior value to the size of the collection. Name of the parameter: index
  • prabunewindia
    New Member
    • Mar 2007
    • 199

    #2
    hi friend,
    see the for loop
    the interval--> i=0;i<=size
    plz delete the = and try
    i=0;i<size
    Prabu
    Originally posted by merinodaniel
    hi all, first post so pls dont be hard with me :p
    well i have this code and i dont know why it says error pls check it :

    double total = 0.0;
    int size = _receipt.Count;
    for (int i = 0; i <= size; i++)
    {
    if ((Receipt)_rece ipt[i] is ItInvoices) //the ERROR is in this line
    {
    ItInvoices itinvoi = (ItInvoices)_re ceipt[i];
    total = total + itinvoi.getNeto ();
    }
    else
    {
    Ticket tick = (Ticket)_receip t[i];
    total = total + tick.getNeto();
    }
    Console.WriteLi ne(total);
    }


    the ERROR says: The index was outside the interval. It must be a nonnegative and inferior value to the size of the collection. Name of the parameter: index

    Comment

    • merinodaniel
      New Member
      • May 2007
      • 5

      #3
      ty, ty, ty, :p i always have this problem in java also :P
      i dont know why i always forgot it jeje
      another doubt how can i show a dialog with some text so i can change this line,


      Console.WriteLi ne(total);



      ty for answer me
      bye

      Comment

      Working...