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. 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
     
    Benoit Vreuninckx, Jan 6, 2005
    #2
    1. Advertisements

  3. Peter

    James Curran Guest


    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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.