473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Unreachable code detected when adding a switch statement

I am getting an error "Unreachable code detected" when I add a switch statement.

My code looks like:

Expand|Select|Wrap|Line Numbers
  1. private void calbtn_click(object sender, EventArgs e)
  2. {
  3.   double regFee;
  4.   double lodging;
  5.   double days;
  6.   string Total
  7.   {
  8.     string course;
  9.     if (courselistbox.SelectedIndex !=-1)
  10.       course=courselistbox.SelectedItem.ToString();
  11.     switch (course)     /// This is where the unreachable code starts////
  12.     { 
  13.       case 1:
  14.         regFee=1000;
  15.         days=200;
  16.         break;
  17.       case 2:
  18.         etc.
  19.         etc.
  20.         break;
  21.     }
  22.   }
  23.  
  24. {
  25.   total=(regFee + days).ToString("c");
  26.   resultlbl.Text="Registration" + total.Tostring();

NOTE(Everything works functionally until I try to add the switch statement. Please due Respond)
Oct 28 '13 #1
2 3374
stdq
94 64KB
Hi! Variable course is a string, but your case labels specify integers. Maybe it should be case "1", for example.
Oct 28 '13 #2
Frinavale
9,735 Expert Mod 8TB
You posted code for part of a method that handles the calbtn_click event.

I don't use C# very often but on line 7 you have an open { and you have the closing } on line 22.

This doesn't seem right to me because you have no if statement or any reason to have these brackets here since you are in the calbtn_click method.

Likewise, you have a random { on line 24...


Line 6 doesn't have a ;

Please correct your syntax.


-Frinny
Oct 29 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: ChrisB | last post by:
I have two pieces of code show below. The first contains a switch statement. The second contains a text shown on the console application screen. The simple menu shows up fine, I enter a number...
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
2
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
9
by: paul c | last post by:
Apologies if I'm sending this to the wrong group. If so I'd be grateful if somebody could point me to the right one. I'm using microsoft visual c++ 6.0 compiler. My code is C, I just use the...
8
by: teddysnips | last post by:
I'm new to C# - recent background mainly ASP.NET with VB.NET. Anyhoot, I needed to create a C# statement analogous to VB's IIf: VB.NET Dim e As Boolean e = IIf((CInt(MyVariable) 0), True,...
3
by: cie | last post by:
Hi, anyone please help me when I try to close a connection to the database from a static method, "Unreachable code detected" error occured. What's the problem actually? Thank you before
1
by: ITC | last post by:
When i write web method in C#. I got a warning and can't get the right result though it run. Code is below. public string CurrencyConverter(double amt, string fromCurrency, string...
2
by: selasebytes | last post by:
how do i get over this warning to get my program running correctly?? Below is the faulty part of the code. Am trying to calculate discount on a purchase form. the codes for my discount is nested in...
23
by: csolomon | last post by:
Hello: I have a form that allows me to add new records. In the onCurrent event, I have: Private Sub Form_Current() 'Requery Job Number Me.cbojobNumber.Requery 'Requery DM_Mix Combo...
5
by: karthik gowda | last post by:
String position = cboPositions.Text; switch (position) { case "Absolute": x = 1; y = 1; break; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.