I know this is possible in Visual Basic. But is something like that possible in c#?
string a = "two"
switch(a)
{
case "one", "two":
DoSomeThing();
break;
}
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 4, 2011, 10:52 AM EST
you have to use it like this: switch(a) { case "one": case "two": DoSomeThing(); break; } HTH Happy Programming!!! Regards, RajaVulpesRank #55 · 29.2K reputationPosted Mar 4, 2011, 1:39 PM EST
If the cases are not empty, then you have to use 'goto case' if you want to jump to another case:
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 5, 2011, 11:28 PM EST
string a = "One";
if (a == "One")
{
DoSomeThing();
}
else if (a == "Two")
{
DoSomeThing();
}
Sam HobbsRank #107 · 20.5K reputationPosted Mar 6, 2011, 2:29 PM EST
Per Jespersen23 reputationPosted Mar 8, 2011, 9:32 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Mar 8, 2011, 9:43 PM EST