-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 = "";
5

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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)

3 Comments

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()!
its the delimiter returning a comma separated list. If you want no spaces then do it with an empty ''
See my answer. There's also a link to the MSDN so that you read more background about Concat().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.