How to convert a char array to a string array
char[] daysCodeArray = days.ToCharArray();
string[] daysArray = daysCodeArray.Select(el =>
{
switch (el)
{
case 'M':
return "Monday";
case 'T':
return "Tuesday";
case 'W':
return "Wednesday";
case 'R':
return "Thursday";
case 'F':
return "Friday";
case 'S':
return "Saturday";
case 'U':
return "Sunday";
}
throw new ArgumentException("Invalid day code");
}).ToArray();
You can change the lambda into a separate method if you want.
Just using char.ToString()
would work:
var daysArray = days.ToCharArray().Select( c => c.ToString()).ToArray();
Alternatively, and a better solution in my mind why don't you use the string directly with a dictionary for the mapping:
var daysArray = days.Select( c => dayMapping[c]).ToArray();
with dayMapping
just a Dictionary<char, string>
that maps to the full day name:
Dictionary<char, string> dayMapping = new Dictionary<char,string>()
{
{ 'M', "Monday" },
{ 'T', "Tuesday" }
//and so on
}