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

  • SEARCH
  • Home
  • 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 9218723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:55:46+00:00 2026-06-18T02:55:46+00:00

Here is the class (relax, it’s just an example and not intended for concrete

  • 0

Here is the class (relax, it’s just an example and not intended for concrete use):

public class Sample
{
    public Sample()
    {
    }

    public string Size
    {
        get
        {
            switch (index)
            {
                case 0: return 100;
                        break;
                case 1: return 500;
                        break;
                case 2: return 1000;
                        break;
                ...
            }
        }
    }
}

I am getting an “Unreachable code detected” error on the break keyword. Is it even possible to write switch statements inside a class or class member function? Or, am I stuck with if-else blocks?

Based on the feedback below, I see I made a silly error, with return preceding the break

  • 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-18T02:55:48+00:00Added an answer on June 18, 2026 at 2:55 am

    You are getting a unreachable code on the break because the code is unreachable. The return ensures that. You can just remove the break statements and everything should work fine.

    You can rewrite the switch in either of these two ways:

    switch(index)
    {
      case 0: return 100;
      case 1: return 500;
      case 2: return 1000;
    }
    

    or

    int value = 0;
    switch(index)
    {
       case 0:
         value = 100;
         break;
       case 1:
         value = 500;
         break;
       case 2:
         value = 1000;
         break;
    }
    return value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{
Here is my class (product.cs) where is the method to insert the image: public
Given the simple example here: class Base @tag = nil def self.tag(v = nil)
I'd like to make class A Parcelable. public class A { public String str;
Can Anyone Tell me why the function is Not Calling Here Class MasterViewController.h @interface
[TestFixture] public class Tests { private class Relay { public Action Do { get;
Here's a code example class person constructor: (@name, @age) -> bob = new person(bob,
I've got this here class defined in a header file: class E_IndexList { public:
See this code here: class test { int n; int *j; public: test(int m)
Anyone know how to redeclare function? For example: class Name{} //Code here class Name{}

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.