C# Array Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m007s
    New Member
    • Mar 2008
    • 1

    C# Array Problem

    All:

    I'm trying to access a simple array like I always do, and running into a problem. I thought it was a simple typo, but experiencing a problem. To debug, I established the a simple array and tested.

    //Debug
    string [] s;

    s = new string [7];
    s[0] = "TEST";

    When moving from the second to last line the watch goes from a value of 'null' (as expected) to 'Does not exist' ????


    [IMG]C:\Temp\Array_E rror_1.jpg[/IMG]
    [IMG]C:\Temp\Array_E rror_2.jpg[/IMG]

    (image insert does not appear to be working) - Debugger reads:

    Name Value
    ========= =============== ========
    s[0].ToString() error: 's[0].ToString' does not exist





    any help appreciated.

    Thanks.



    MS
  • mailmesuren
    New Member
    • Mar 2008
    • 1

    #2
    I hope ,its not possible to intialize value to string array after declaration.
    Instead,you can try Arraylist.
    eg:
    Arraylistobj.Ad d("TEST");

    Comment

    • blackjack2150
      New Member
      • Feb 2007
      • 79

      #3
      Originally posted by mailmesuren
      I hope ,its not possible to intialize value to string array after declaration.
      Instead,you can try Arraylist.
      eg:
      Arraylistobj.Ad d("TEST");
      Do not use ArrayList!!

      In .NET 2.0 ArrayList has been replaced by List<>. It is much much faster because you can specify which type the object in the list are, so boxing-unboxing operations are not necessary.

      example:
      List<string> myStringList = new List<string>();

      myStringList.Ad d("aaa");
      myStringList.Ad d("bbb");

      you can also easily remove items, sort the List, etc. And you have direct access to the methods of the string class with no explicit conversion required since it's already strong-typed.


      ex:

      string s = myStringList[0].ToUpper();

      Comment

      Working...