-1

I have C# code like this:

  if (OldStatus = activityStatus.Complete) or (OldStatus = activityStatus.Cancelled)...

In Delphi I would have written

  if OldStatus in (Complete, Cancelled) then...

Is there any equivalent to this use of a set in C# or do I need to spell out each option as above (or use a switch/case). (Sorry if the question is basic; I'm new to C#.)

Eric
  • 142
  • 1
  • 13

2 Answers2

1

There is no language feature for this. You can simulate it by "spelling it out" as you say, or with an if/else chain, a switch, using a HashSet<T>, etc. -- the proper answer is case-specific, they're all valid in different circumstances.

Cory Nelson
  • 29,236
  • 5
  • 72
  • 110
0

If you're looking for an enum value, and that enum is marked with the [Flags] attribute, then you could use a bitmask to determine if the required value is present - as demonstrated in this answer, otherwise, the switch, if/else etc.. apply.

Community
  • 1
  • 1
dyson
  • 866
  • 6
  • 12