Skip to content

Instantly share code, notes, and snippets.

@profesor79
Created February 14, 2023 11:12
Show Gist options
  • Save profesor79/17c18982fffa07b537ec2832714b1993 to your computer and use it in GitHub Desktop.
Save profesor79/17c18982fffa07b537ec2832714b1993 to your computer and use it in GitHub Desktop.
if VS switch - a total war
public class SwitchStuff
{
[Benchmark]
[Arguments("ThisIsCase1")]
[Arguments("ThisIsCase2")]
[Arguments("ThisIsCase3")]
[Arguments("ThisIsCase4")]
[Arguments("ThisIsCase5")]
public string ProcessSwitchWithString(string matchCase)
{
switch (matchCase)
{
case "ThisIsCase1":
return "case1";
case "ThisIsCase2":
return "case2";
case "ThisIsCase3":
return "case3";
case "ThisIsCase4":
return "case4";
case "ThisIsCase5":
return "case5";
}
return string.Empty;
}
}
public class IfStuff
{
[Benchmark]
[Arguments("ThisIsCase1")]
[Arguments("ThisIsCase2")]
[Arguments("ThisIsCase3")]
[Arguments("ThisIsCase4")]
[Arguments("ThisIsCase5")]
public string ProcessIfWithString(string matchCase)
{
if (matchCase == "ThisIsCase1")
{
return "case1";
}
else if (matchCase == "ThisIsCase2")
{
return "case2";
}
else if (matchCase == "ThisIsCase3")
{
return "case3";
}
else if (matchCase == "ThisIsCase4")
{
return "case4";
}
else if (matchCase == "ThisIsCase5")
{
return "case5";
}
return string.Empty;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment