Skip to content

Instantly share code, notes, and snippets.

@MohammedAbuissa
MohammedAbuissa / SwitchInsteadOfIf.csx
Last active January 14, 2017 20:44
This code shows a way to use switch statement instead of if statement by encoding conditons results as int. The motivation, behind this, is that switch statements normally have better performance than if statement, because compilers create a table of function pointer for switch which avoids the branching that normally slow down the execution of …
using System.Diagnostics;
class Solution {
static Dictionary<bool, int> BoolToInt = new Dictionary<bool, int>()
{
{false, 0},
{true,1}
};
public static void Main(String[] args) {