switch-statement

Would you use regions within long switch/enum declarations?

爷,独闯天下 提交于 2019-12-23 09:01:45
问题 I've recently found myself needing (yes, needing) to define absurdly long switch statements and enum declarations in C# code, but I'm wondering what people feel is the best way to split them into logical subsections. In my situation, both the enum values and the cases (which are based on the enum values) have fairly clear groupings, yet I am slightly unsure how to reflect this in code. Note that in my code, I have roughly 5 groups of between 10 and 30 enum values/cases each. The three vaguely

Why can I not use a “constant” within a switch statement within scope?

时光毁灭记忆、已成空白 提交于 2019-12-23 07:08:30
问题 With this code: public partial class Form1 : Form { private static readonly int TABCONTROL_BASICINFO = 0; private static readonly int TABCONTROL_CONFIDENTIALINFO = 1; private static readonly int TABCONTROL_ROLESANDSECURITY = 2; private static readonly int TABCONTROL_INACTIVEINFO = 3; . . . int ActiveTabPage = tabControlWorker.SelectedIndex; switch (ActiveTabPage) { case TABCONTROL_BASICINFO: if (currentNode == "NodeBuckingham") { } else if (currentNode == "NodeNamath") { } else if

At what stage does an if/else become better than a switch case? Does it?

橙三吉。 提交于 2019-12-23 06:48:46
问题 From what I have read I can summarize, Switch case is implementation defined but is mostly defined as a jump table Switch case makes the code more readable Switch is faster than if/elseif (?) Consider a case where I have 300+ switch cases. I know an if/elseif in this scene will be a mess. But I want to know how will a switch case perform in such a scene? Is it scalable i.e it remains relatively faster than an if/else no matter how many cases are present ? Since it is implementation defined

Getting input from user with Switch C++

此生再无相见时 提交于 2019-12-23 06:31:08
问题 I have a system where user can enter as many inputs as s/he wants and make some calculations. Here is the code for achieving this task: int main() { char op = 's'; float time=0, fuel_rate=0, start=0, end=0, pace=0; while(op != 'x'){ cout << "Please select: " << endl; cout << "1 ---> A" << endl; cout << "2 ---> B" << endl; cout << "3 ---> Calculate" << endl; cout << "x ---> Exit" << endl; op = std::getchar(); //remove the rest of the line from input stream int temp; while ( (temp = std:

Assembly code for a switch statement using AVR-GCC

江枫思渺然 提交于 2019-12-23 05:25:51
问题 Hey I am having trouble understanding the assembly code omitted by the compiler for the following switch statemet. It is different than the usual assembly code I see from using gcc etc. switch(instr) { case OP_NOP: break; case OP_BIPUSH: stack_push(arg0.z.bh); pc_inc = 2; break; } Assembly code for the above C code: switch(instr){ +00001482: 8529 LDD R18,Y+9 Load indirect with displacement +00001483: 2F82 MOV R24,R18 Copy register +00001484: E090 LDI R25,0x00 Load immediate +00001485: 01FC

C# SessionSwitchReason.SessionLock NOT triggering when machine is locked via Group Policy

别等时光非礼了梦想. 提交于 2019-12-23 05:24:00
问题 EDIT: The issue here wan't the fact it was locked via GP, it was that it was being run as a service under a service account and it didn't have access to the interactive desktop I have a C# application that needs to check for when a user's session is locked, I'm using Microsoft.Win32.SystemEvents.SessionSwitch and this works fine when a user manually locks the machine. The problem is that when the machine is locked via a group policy (User Configuration > Policies > Administrative Templates >

Alternative for multiple IF/CASE statements

淺唱寂寞╮ 提交于 2019-12-23 05:15:54
问题 Is there a way to avoid multiple IF/CASE statements in C#? In my app I will end up with 8+ fields used to create a Linq query where every expression can be null or != null so it will give me 64 scenarios. I'm not providing any code samples because I can do it using IF/CASE and simplify it as much as I can. If You are familiar with some useful approaches to that problem I will appreciate any advice. Code Sample (it only includes two delegates but I'll have to add more to filter data)

Angular 2 - ngSwitchCase

淺唱寂寞╮ 提交于 2019-12-23 04:33:33
问题 I'm learning Switch Case with Angular 2. I'm trying to echo array, but I've have to rename some words. This is what I've before : <tbody *ngFor="let access of menu.navAccess" class="tr-content"> <tr class="trParent"> <td>{{ access.access | uppercase }}</td> <td>{{ access.accessType }}</td> <td><span class="glyphicon glyphicon-trash actionsBtn" data-toggle="modal" data-target="#deleteModal" (click)="showDelete(access)"></span></td> </tr> </tbody> Now, I want to include ngSwitchCase on access

PHP include external swich not working

自古美人都是妖i 提交于 2019-12-23 02:45:12
问题 I have the following snippet which works fine, but I want the switches switch ($fixture->homeTeamName) and switch ($fixture->awayTeamName) to be included from external file named swich_1.php not hard coded in the template, but I failed to include it: <table class="table table-striped"> <tr> <th>HomeTeam</th> <th></th> <th>AwayTeam</th> <th colspan="3">Result</th> </tr> <?php foreach ($soccerseason->getFixturesByMatchday(1) as $fixture) { switch ($fixture->homeTeamName) { case 'Walsall FC':

refactoring and removing case statements when circling over an enum structure

放肆的年华 提交于 2019-12-23 02:42:16
问题 An enum structure declared in its own class is a member variable to the business logic class. That enum basically represents the state of that other class. Although I have revisited the issue several times, replacing, or getting rid of those case statements proves quite frustrating to me. Several business logic methods simple iterate over the enum and change the state of that class by assigning another value of the same enum, and other properties. public enum MyEnum{ A,B,C,D } The business