As I was working on this answer, I've written some code to convert a generic multi-dimensional collection to a string.
public static string ConvertToString<T>(this IEnumerable<IEnumerable<T>> input, string columnSplit = "", string rowSplit = "\n")
{
return string.Join(rowSplit, input.Select(r => string.Concat(string.Join(columnSplit, r.Select(c => c.ToString())))));
}
Example Input
IEnumerable<IEnumerable<string>> input = new List<List<string>>
{
new List<string> { "R", "L", "R", "R" },
new List<string> { "L", "R", "V", "R" },
new List<string> { "L", "R", "V", "R" },
new List<string> { "R", "L", "L", "R" },
};
Desired Output
RLRR
LRVR
LRVR
RLLR
Although the code works, I don't find the solution to be elegant with the fact that it requires a string.Join
inside a string.Concat
inside a Select
. Is there a way to simplify this solution.