ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

In

Checks if object is any of provided values separated by comma

Source

public static bool In<T>(this T s, params T[] values)
{
    return values.Any(x => x.Equals(s));
}

Example

public enum VehicleType
{
    Car,
    Bike,
    Truck,
    Bus
}

public bool IsCarOrBike(VehicleType vehicle)
{
    return vehicle.In(VehicleType.Car, VehicleType.Bike);
}

public bool IsValidGender(string textToValidate)
{
    return textToValidate.In("m", "f", "male", "female");
}

Author: Ivan Ferić

Submitted on: 12 mei 2011

Language: C#

Type: System.Object

Views: 4593