In
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");
}
Description
Checks if object is any of provided values separated by comma
Details
- Author: Ivan Ferić
- Submitted on: 12-5-2011 19:57:55
- Language: C#
- Type: System.Object
- Views: 267
Double click on the code to select all.


