Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:36:21+00:00 2026-06-13T21:36:21+00:00

class AddItemOption { //Fields that contain class data string input = Console.ReadLine(); //Methods that

  • 0
 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;


        }

    }

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!

   public AddItemOption(string input) 

        {


        }

FROM Shyju I changed it to:

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;


        }
    }

However, it does not recognize the breaks. “Unreachable Code Detected”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:36:23+00:00Added an answer on June 13, 2026 at 9:36 pm

    Your method has a return type of string. That means your method should always return some string. But you are not returning a string. instead you are Writing it to the console using WriteLine method.

    So Change

    Console.WriteLine("Umbrella is selected");
    

    to

    return "Umbrella is selected";
    

    OR

    You can change your method’s return type to void.

     public void myFunction(string Value)
     {
       //your current fancy stuff here
       Console.WriteLine("My method dont have a return type");
     }
    

    EDIT : AS per the question edit.

    return statement will take the control out from your method. that means the next line (break) won’t be executed. So remove the break statement.

     case "Key Chain":
               return "Key Chain is selected";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { static void Main(string[] args) { Console.WriteLine(Fib 1: ); Console.ReadLine(); } long
class Test { public static void main(String[] args) throws Exception { Test t =
class Foo() { public Bar [] bars; } class Bar () { public string
class A { public static void main(String[] args) { A a = new A();
class TreeNode { public string Value { get; set;} public Collection<TreeNode> Nodes { get;
class A { String s4 = abc; static public void main(String[]args ) { String
class Monitor { public: Monitor(string someData); Person person_; } class Person { public: Person(string
class Main { public static void main(String[] args) { new Cloned().clone(); } } class
class A { public: A(…) {…} virtual ~A() {…} private: // may contains data
class Monitor { TheManager manager; Map<String, Subject> subjectMap; public Monitor() { TheManager manager =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.