I think the Commodore 128 Basic had a statement.
Does the operator in C # also?
I mean, there is an operator of the form
if(aString in ["a", "b", "c"]) Console.Out.WriteLine("aString is 'a', 'b' or 'c'");
Edit1: Currently, I need to determine if the enum value has a range of enum values.
Edit2: Thanks to everyone for the solutions to Contains (). I will use it in the future. But currently I have a need for enumeration values. Is it possible to replace the following statement with Contains () or other methods?
public enum MyEnum { A, B, C } class MyEnumHelper { void IsSpecialSet(MyEnum e) { return e in [MyEnum.A, MyEnum.C] } }
Edit3: Sorry, this was not Basic. I was just looking for hiking and found Turbo Pascal as a candidate where I could see him. See http://en.wikipedia.org/wiki/Pascal_%28programming_language%29#Set_types
Edit4: The best answers to date (end February 15, 2012):
- For lists and arrays: accepted answer and all other answers with Contains () solutions
- For Enums: Kaneda's answer with a good list of pros and cons for various extension methods
source share