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 = "";
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 = "";
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.
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)