Array of StringBuilder

Discussion in 'Microsoft C# .NET' started by Peter, Jan 6, 2005.

  1. Peter

    Peter Guest

    Hi,

    A newbie question ..

    I want to use an array of length 4 while each array element
    is a string of 40 chars.

    I typed ..
    StringBuilder title = new StringBuilder(40)[4];

    Now I suppose that title[0] is a string of 40 chars; same
    for title[1], title[2], title[3].

    VS .NET complains with "cant convert char to StringBuilder
    ", but why ??

    And what's then the correct solution for my problem ?

    Thanks
    P.
     
    Peter, Jan 6, 2005
    #1
    1. Advertisements

  2. Peter wrote:
    > Hi,
    >
    > A newbie question ..
    >
    > I want to use an array of length 4 while each array element
    > is a string of 40 chars.
    >
    > I typed ..
    > StringBuilder title = new StringBuilder(40)[4];


    should be: StringBuilder[] title = new StringBuilder[4];
    to create an array to hold the stringbuilder objects

    now you (still) have to create each of the 4 stringbuilder objects:

    title[0] = new StringBuilder(40);
    title[1] = new StringBuilder(40);
    title[2] = new StringBuilder(40);
    title[3] = new StringBuilder(40);


    Greetings

    >
    > Now I suppose that title[0] is a string of 40 chars; same
    > for title[1], title[2], title[3].
    >
    > VS .NET complains with "cant convert char to StringBuilder
    > ", but why ??
    >
    > And what's then the correct solution for my problem ?
    >
    > Thanks
    > P.
    >
    >
    >
    >
     
    Benoit Vreuninckx, Jan 6, 2005
    #2
    1. Advertisements

  3. Peter

    James Curran Guest

    "Peter" <> wrote in message
    news:...
    > I typed ..
    > StringBuilder title = new StringBuilder(40)[4];
    >
    > VS .NET complains with "cant convert char to StringBuilder
    > ", but why ??



    Consider the following:

    StringBuilder title = new StringBuilder(40);
    char c = title[4];

    Make sense? Now slide it all together, and you'll see why "new
    StringBuilder(40)[4]" is a char.

    --
    Truth,
    James Curran
    [erstwhile VC++ MVP]
    Home: www.noveltheory.com Work: www.njtheater.com
    Blog: www.honestillusion.com Day Job: www.partsearch.com
     
    James Curran, Jan 6, 2005
    #3
    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. Hans Kesting

    Re: Why use StringBuilder instead of string

    Hans Kesting, Aug 4, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    332
  2. Alvin Bruney

    StringBuilder

    Alvin Bruney, Sep 18, 2003, in forum: Microsoft C# .NET
    Replies:
    16
    Views:
    351
    Alvin Bruney
    Sep 21, 2003
  3. Alvin Bruney

    StringBuilder

    Alvin Bruney, Sep 23, 2003, in forum: Microsoft C# .NET
    Replies:
    19
    Views:
    349
    Alvin Bruney
    Sep 25, 2003
  4. Arjen

    Split stringbuilder in array

    Arjen, Oct 14, 2005, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    1,001
    Kevin Spencer
    Oct 14, 2005
  5. Peter

    StringBuilder to byte array

    Peter, Nov 20, 2007, in forum: Microsoft C# .NET
    Replies:
    16
    Views:
    1,976
    Jon Skeet [C# MVP]
    Nov 21, 2007
Loading...

Share This Page