Given Is The Code Of Daysexample8221mtwtfss8221 Which I Need To #28
Given is the code of days(example:”MTWTFSS”) which I need to split and hence create a list of days of week in strings( example:”Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”). A set of code is given for this purpose but there is the error occurring in that set of code related to the conversion of char to strings. Hence, Select a C# code to solve the given error.</p> <pre><code class="language-csharp" line="1"> static void Main(string[] args) { var days = "MTWTFSS"; var daysArray = days.ToCharArray().Cast<string>().ToArray(); for (var i = 0; i < daysArray.Length; i++) { switch (daysArray[i]) { case "M": daysArray[i] = "Monday"; break; case "T": daysArray[i] = "Tuesday"; break; case "W": daysArray[i] = "Wednesday"; break; case "R": daysArray[i] = "Thursday"; break; case "F": daysArray[i] = "Friday"; break; case "S": daysArray[i] = "Saturday"; break; case "U": daysArray[i] = "Sunday"; break; } } daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1]; Console.WriteLine(string.Join(", ", daysArray)); } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs108 CSharp. It can also be found in gs gs108 Data Types, Variables and Operators - Char Types and String Literals - Quiz No.1.
Given is the code of days(example:”MTWTFSS”) which I need to split and hence create a list of days of week in strings( example:”Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”). A set of code is given for this purpose but there is the error occurring in that set of code related to the conversion of char to strings. Hence, Select a C# code to solve the given error.
static void Main(string[] args) { var days = "MTWTFSS"; var daysArray = days.ToCharArray().Cast<string>().ToArray(); for (var i = 0; i < daysArray.Length; i++) { switch (daysArray[i]) { case "M": daysArray[i] = "Monday"; break; case "T": daysArray[i] = "Tuesday"; break; case "W": daysArray[i] = "Wednesday"; break; case "R": daysArray[i] = "Thursday"; break; case "F": daysArray[i] = "Friday"; break; case "S": daysArray[i] = "Saturday"; break; case "U": daysArray[i] = "Sunday"; break; } } daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1]; Console.WriteLine(string.Join(", ", daysArray)); }
var daysArray = new List<String>();
var daysArray = days.Select(c =>dayMapping[c]).ToArray();
var daysArray = days.ToCharArray().Select(c =>c.Tostring()).ToArray();
var daysArray = days.Select<String>();