KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm looking to combine the contents of two string arrays, into a new list that has the contents of both joined together. string[] days = { "Mon", "Tue", "Wed" }; string[] months = { "Jan", "Feb", "Mar" }; // I want the output to be a list with the contents // "Mon Jan", "Mon Feb", "Mon Mar", "Tue Jan", "Tue Feb" etc... How can I do it ? For when it's only two arrays, the following works and is easy enough: List<string> CombineWords(string[] wordsOne, string[] wordsTwo) { var combinedWords = new List<string>(); foreach (var wordOne in wordsOne) { foreach (string wordTwo in wordsTwo) { combinedWords.Add(wordOne + " " + wordTwo); } } return combinedWords; } But I'd like to be able to pass varying numbers of arrays in (i.e. to have a method with the signature below) and have it still work. List<string> CombineWords(params string[][] arraysOfWords) { // what needs to go here ? } Or some other solution would be great. If it's possible to do this simply with Linq, even better!
Tags (comma-separated)
Save Edits
Cancel