Array of StringBuilder

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

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 said:
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.
 
Peter said:
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
 
Back
Top