I think there was an in operator in Commodore 128 Basic.
Is there an in operator in c# too?
I mean is there an operator of kind
if(aString in ["a", "b", "c"])
Console.Out.WriteLine("aString is 'a', 'b' or 'c'");
Edit1: Currently I need it to decide if an enum value is in a range of some enum values.
Edit2: Thank you all for the Contains() solutions. I will use it in the future. But currently I have a need for enum values. Can I 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 it was not Basic. I just googled a while and found Turbo Pascal as a candidate where I could saw it. See http://en.wikipedia.org/wiki/Pascal_%28programming_language%29#Set_types
Edit4: Best answers up to now (end of 15 Feb 2012):
- For lists and arrays: accepted answer and all other answers with
Contains() solutions - For Enums: TheKaneda’s answer with good list of pros/cons for
different extension methods
Try this:
This uses the
Containsmethod to search the array foraString.