Given:
A string dayCodes
(i.e. \"MWF\"
or \"MRFU\"
) that I need to split and create a collection of strings so I
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.