Note that there are some explanatory texts on larger screens.

plurals
  1. POClasses with String Switches
    primarykey
    data
    text
    <pre><code> class AddItemOption { //Fields that contain class data string input = Console.ReadLine(); //Methods that define class functionality public string myFunction(string Value) { switch (input) { case "Umbrella": Console.WriteLine("Umbrella is selected"); break; case "Rain Coat": Console.WriteLine("Raincoat is selected"); break; case "Boots": Console.WriteLine("Boots is selected"); break; case "Hood": Console.WriteLine("Hood is selected"); break; default: Console.WriteLine("Input not reconized, please choose another item"); break; } } </code></pre> <p>I get the error "Not all code paths return a value". It is from myFunction(string Value). I'm not sure how to return this, or what to put in the parameter to get it to work. Do I need something below it too? I am new to classes. Please tell me if I'm doing this all wrong or if that is where the switch statement should go! </p> <pre><code> public AddItemOption(string input) { } </code></pre> <p>FROM Shyju I changed it to:</p> <pre><code>class AddItemOptionOne { //Fields that contain class data string input = Console.ReadLine(); //Methods that define class functionality public string myFunction(string Value) { switch (input) { case "Key Chain": return "Key Chain is selected"; break; case "Leather Armor": return "Leather Armor is selected"; break; case "Boots": return "Boots is selected"; break; case "Sword": return "Sword is selected"; break; default: return "Input not reconized, please choose another item"; break; } } </code></pre> <p>However, it does not recognize the breaks. "Unreachable Code Detected"</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload