1

I have two List

//Two input string[] 

String[] a = {"abc", "cdf"};
string[] b ={"hhh", "ggg"};

//Output string[] c should return as below

string[] c = {"abc:hhh", "cdf:ggg"};

Tried using below code:

var res = a.Zip(b, (n, w) => new { uppercase = n, lowercase = w }); 

but how to assign this result to output string[] c?

0

1 Answer 1

3

You can use Zip and concat the strings like this:

string[] c = a.Zip(b, (x, y) => $"{x}:{y}").ToArray();

In your example you created a new instance of an anonymous type (new {uppercae = n, lowercase = w}). But your desired output shows you want to combine the strings with a :. That's what `$"{x}:{y}" does in the code above.

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

Comments

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.