-4

I want to put an array of strings to a string value. What is the fastest way to copy mm to k?

string[] mm = new string[1,000,000]; // its just sample
string k = "";
Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62

2 Answers2

0

Assuming your definition of mm changes to something like this ...

string[] mm = {"Dog", "Cat", "Mouse"};

... you can concatenate all strings of the array mm into one string using the Concat() method such as like this:

string k = System.String.Concat(mm);

It is possible that there is a faster way, but this is a convenient way to use an existing .NET Framework method which is already very well optimized.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
-2

Is this what you are looking for?

string k = String.Join("",mm)`

Use the String.Join method which accepts the array and a delimiter

BTW, your array does not have string values

If you do not need any spaces/separators between the parts you can use String.Concat which accepts a list of strings

string k = String.Concat(mm)
M B
  • 2,326
  • 24
  • 33
  • The `Join()` method starts with a delimiter, not the array. Also, the PO wasn't asking for adding delimiters in between the strings. Use `Concat()`! – Quality Catalyst May 16 '16 at 19:27
  • its the delimiter returning a comma separated list. If you want no spaces then do it with an empty `''` – M B May 16 '16 at 19:27
  • See my answer. There's also a link to the MSDN so that you read more background about `Concat()`. – Quality Catalyst May 16 '16 at 19:37