I suggest you ...

switch case

Add a switch statement of selection by type:

switch (typeof(myvar))
{
case TypeA; ActionA; break;
case TypeB; ActionB; break;
}

1 vote
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Willem-Derk Nijdam shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Philippe commented  ·   ·  Flag as inappropriate

    Although if would be nice if switch was more flexible as in some other languages (F#, Swift...), in that case, this is typically a poor design. You should usually either use virtual functions or a visitor pattern for that purpose.

Feedback and Knowledge Base