using ArrayList Collection class

Discussion in 'Microsoft C# .NET' started by Guest, Apr 28, 2006.

  1. Guest

    Guest Guest

    (Sorry if this is a re-post, don't think it worked the first time)

    Hello,

    I am trying to add an ArrayList as a field in my web form class.

    Here is a sample:

    using System;
    using System.Collections;
    ....

    ArrayList myArrayList = new ArrayList();
    myArrayList.Add("Belleck Colleen Vase");
    myArrayList.Add("Belinda Bradshaw Cat Bowl");
    myArrayList.Add("Nicholas Mosse Cat Mug");
    myArrayList.Add("Shamrock Paperweight");
    myArrayList.Add("Business Card Holder");

    When trying to build this web form I get the error
    "Invalid tocken '(' in class, struct, or interface member declaration"

    Does anyone know why I can't add an ArrayList as a field in my web form
    class? I want to be able to access my ArrayList in different methods within
    my web form.

    Thanks
     
    Guest, Apr 28, 2006
    #1
    1. Advertisements

  2. Guest

    Alex Li Guest

    Diatom,

    Seems like you have an extra ( in your code somewhere.... it is
    probably just syntax error, not anything related to ArrayList at all.

    HTH,
    Alex
     
    Alex Li, Apr 28, 2006
    #2
    1. Advertisements

  3. Guest

    Barry Kelly Guest

    am <> wrote:

    > myArrayList.Add("Belleck Colleen Vase");
    > myArrayList.Add("Belinda Bradshaw Cat Bowl");
    > myArrayList.Add("Nicholas Mosse Cat Mug");
    > myArrayList.Add("Shamrock Paperweight");
    > myArrayList.Add("Business Card Holder");


    You can only put these statements in a method body. You must implement an
    event, override a method, or create a new method and place these
    statements inside the method body.

    -- Barry
     
    Barry Kelly, Apr 28, 2006
    #3
  4. Hi,

    Use an array instead. if you know a priori the content of it.


    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation


    "" <> wrote in
    message news:...
    > (Sorry if this is a re-post, don't think it worked the first time)
    >
    > Hello,
    >
    > I am trying to add an ArrayList as a field in my web form class.
    >
    > Here is a sample:
    >
    > using System;
    > using System.Collections;
    > ...
    >
    > ArrayList myArrayList = new ArrayList();
    > myArrayList.Add("Belleck Colleen Vase");
    > myArrayList.Add("Belinda Bradshaw Cat Bowl");
    > myArrayList.Add("Nicholas Mosse Cat Mug");
    > myArrayList.Add("Shamrock Paperweight");
    > myArrayList.Add("Business Card Holder");
    >
    > When trying to build this web form I get the error
    > "Invalid tocken '(' in class, struct, or interface member declaration"
    >
    > Does anyone know why I can't add an ArrayList as a field in my web form
    > class? I want to be able to access my ArrayList in different methods
    > within
    > my web form.
    >
    > Thanks
     
    Ignacio Machin \( .NET/ C# MVP \), Apr 28, 2006
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    RE: Iterate through an ArrayList using values in another ArrayList

    Saravanan Rathinavelu, Aug 18, 2003, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    366
    Saravanan Rathinavelu
    Aug 26, 2003
  2. Gustaf Liljegren

    Adding an ArrayList to an ArrayList?

    Gustaf Liljegren, Nov 4, 2003, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    304
    Gustaf Liljegren
    Nov 4, 2003
  3. will

    copy ArrayList to ArrayList

    will, Feb 21, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    280
    Justin Rogers
    Feb 21, 2004
  4. Guest

    using ArrayList Collection Class

    Guest, Apr 28, 2006, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    182
    Ignacio Machin \( .NET/ C# MVP \)
    May 1, 2006
  5. Guest

    ArrayList Class Vs. List Generic Class

    Guest, Jun 15, 2007, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    432
    Jon Skeet [C# MVP]
    Jun 15, 2007
Loading...

Share This Page