Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert array to a string (reverse if split)

Status
Not open for further replies.

m4pv

Programmer
Sep 10, 2004
5
US
Hi!
Is there a way in C# to convert an array to a string without looping through it?
arItems[0] = "A";
arItems[1] = "B";
and string sItems should be "A, B".

Thanks
 
other than:
Code:
string NotSplit = arItems[0] + arItems[1];

You can use foreach if you don't know how many elements there are (even though this is technically the same as looping):
Code:
foreach(string s in arItems){
  NotSplit += s;
  }
 
Thanks, oppcos.
Actually I just found it - I needed "String.Join" method.
 
Hm, .NET framework has a lot of ways to do the same thing. I wouldn't have thought that specific of a method existed, but I should have looked for it first I guess. :)
 
m4pv, I you have a lot of items in the array, I would think the foreach would be more elegant than a bunch of joins.

oppcos, The very richness of the .NET framework can actually make it more difficult to deal with at times. You start researching how to do something, find 10 different examples, some of which are are simply brutal. Then you find a 2 line sweet solution coming out of a completely different namespace, none of the others thought of looking in. Some of the shortcomings are surprising, but on the other hand the depth of the library is amazing at times.



[purple]Jeff
It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top