How to store an array in a string?

Asked

Viewed 494 times

4

Example:

string x;
string[] y = {"5", "0","0","5","5"};
x = "50055"

I want to put it all together into one variable. I will store in a variable not print.

2 answers

7


2

You can use the String.Join when you need a separator. So:

string[] nomes = {"Vinicius", "Rovann", "Anderson"};
return string.Join(";", nomes);
// Saída: "Vinicius;Rovann;Anderson"    

If you want to concatenate an array of strings into a single string, you can use String.Concat. Behold:

string[] arr = {"1", "2", "3"};
return string.Concat(arr);
// Saída: "123"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.