switch-statement

Is there a way to have the c# compiler display warnings when a switch statement do have unhandled cases ?

Consider the following code : private enum myEnum { A, B } private void myMethod(myEnum m) { switch (m) { case myEnum.A: //do stuff break; case myEnum.B: //do stuf...

Using Case/Switch and GetType to determine the object

If you want to switch on a type of object, what is the best way to do this? Code snippet private int GetNodeType(NodeDTO node) { switch (node.GetType()) { case typeof(CasusNodeDTO): return 1; case typeof(BucketNodeDTO): return 3; case typeof(BranchNodeDTO): return 0; ...

[Django Templates] How to get 'switch-case' statement functionality in Django templates?

Hi, I found a link to have a 'switch' tag in Django templates, but I was wondering if this can be somehow achieved without it. Using only the stuff which comes with Django? Basically is there other way then using multiple 'if' or 'ifequal' statements? Thanks in advance for any tips/suggestions. ...

Powershell v1: Is it possible to assign the result of a switch statement to a variable?

Is it possible to assign the result of a switch statement to a variable. For example, instead of: switch ($Extension) { doc {$Location = "C:\Users\username\Documents\"; break} exe {$Location = "C:\Users\username\Downloads\"; break} default {$Location = "C:\Users\username\Desktop\"} } Is it possible ...

Switch/toggle div (jquery)

Hello. I wish to accomplish a simple task (I hope!) I got two div tags and 1 anchor tags, like this: <a href="javascript:void(0);">forgot password?</a> <div id="login-form"></div> <div id="recover-password" style="display:none;"></div> What I wish to accomplish is use the anchor tag to toggle between the two div tags, hide the one a...

How to stop C#'s switch statement from generating the CIL switch instruction

C#'s switch statement can compile to a CIL switch instruction, or if/else's, depending on the cases in the statement as mentioned here. Is there a way to force the compiler to always generate the if/else variant in a block of code? ...

Two if statements?

I have two if statements and my project sees one and not the other. Here is the code: If (IsPostBack) Then HandleUploadedFile() End If Dim savePath As String = "Images\ " If (fileUpload.HasFile) Then Dim fileName As String = fileUpload.FileName savePath = Server.MapPath(savePath) + fileName fileUpload.SaveAs(savePath) Me.Lab...

In PHP can I get the total number of case statements in a switch statement?

Is there a way to return the total number of (case) instances there are in a switch statement? Something like this: $id = $_GET['id']; switch ($id) { case "item1" : $data = 'something1'; break; case "item2" : $data = 'something2'; break; } echo $data; But the reasoning for it is there are multiple files with these switc...

VB.NET Switch Statement GoTo Case

I am writing some code in VB.NET that uses a switch statement but in one of the cases it needs to jump to another block. In C# it would look like this: switch (parameter) { case "userID": // does something here. case "packageID": // does something here. case "mvrType": ...

Bank switching in PIC assembler

I'm getting confused by bank switching in PIC assembler... This works for putting a 'Q' on the usart: bsf PORTB,1 ;Set Transmit DIR (PORTB (0x6) not mirrored in other banks) movlw 'Q' ;'Q' to work reg movwf TXREG ;work reg to TXREG (TXREG (0x19) not mirrored in other banks) clrwdt ;Clear watchdog b...

Enum & Switch Case

Hi I am using enums converted to a string with a switch but it doesn't work. It gives compilation error: Cannot implicitly convert type 'userControl_commontop.UserType' to 'string' The code is: private void CommonTopChangesnew(string usertype) { switch (usertype.Trim().ToUpper()) { case UserType.NORMAL : hl...

Using || in Case switch in Rails

I have a partial that I want to display in a layout only when certain pages use that layout. I've set @page_title for all my pages and thought I could use something like this: <% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%> But, the incl...

Obtain a switch/case behaviour in Perl 5

Is there a neat way of making a case or switch statement in Perl 5?. It seems to me they should include a switch on version 6.. I need this control structure in a script, and I've heard you can import a "switch module". But how can I achieve it without imports to minimize dependencies and acquire portability? ...

Visual studio, how to output time taken to build?

Hi, I'm using visual studio 2005. I rememeber in the back of my mind there's a way to output the time taken to build a given project. Can anyone remember what that switch is? Thanks Rich ...

C++ Custom Enum Struct for INI file reader

I'm trying to create an Enum that has a string label and a value and I plan to use this to read stuff from an ini file. For example in the ini file I might have some double, int or string type values preceded by the tag/name of the value: SomeFloat = 0.5 SomeInteger = 5 FileName = ../Data/xor.csv When I read the tag from a file it co...

C# switch variable initialization: Why does this code NOT cause a compiler error or a runtime error?

... case 1: string x = "SomeString"; ... break; case 2: x = "SomeOtherString"; ... break; ... Is there something that I am not understanding about the switch statement in C#? Why would this not be an error when case 2 is used? Edit: This code works and doesn't throw an error. ...

Is there a template or something for generating a switch statement for Java enum in Eclipse?

Is there a template or something for generating a switch statement for Java enum in Eclipse? So that when I got an enum and I want to have a switch with all the values, I didn't have to write all it myself? ...

Is it legal to switch on a constant in C++?

I was just made aware of a bug I introduced, the thing that surprised me is that it compiled, is it legal to switch on a constant? Visual Studio 8 and Comeau both accept it (with no warnings). switch(42) { // simplified version, this wasn't a literal in real life case 1: std::cout << "This is of course, imposible" << std:...

Overhead of a switch statement in C

Hi all! I'm a fairly competent Java programmer who's very new to C. I am trying to optimize a routine that has four modes of operation. I loop over all the pixels in an image and compute a new pixel value depending on the 'mode' passed. My question regards the overhead of a switch statement within two nested for loops. I'd be interest...

Refactoring advice for big switches in C#

I have an application in C#/Winforms that lets users place objects on a grid to create levels for a game. It has several tools for placing tiles/lights/doors/entities etc. Currently I just use an enum for storing the currently selected tool and have a switch statement to run each tools code. As I've been adding more tools to the applicat...