Decimal - In
A T extension method to determines whether the object is equal to any of the provided values.
public static void Main() { Decimal searchVal = 7.64m; decimal[] values = { 32.7865m, 7.03m, 7.64m, 0.12m, -0.12m, -7.1m, -7.6m, -32.9012m }; // C# Extension Method: Decimal - In if(searchVal.In(values)) { Console.WriteLine("{0} exists in the list.", searchVal); } else { Console.WriteLine("{0} doesn't exists in the list.", searchVal); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A T extension method to determines whether the object is equal to any of the provided values. /// </summary> /// <param name="this">The object to be compared.</param> /// <param name="values">The value list to compare with the object.</param> /// <returns>true if the values list contains the object, else false.</returns> /// ### /// <typeparam name="T">Generic type parameter.</typeparam> public static bool In(this Decimal @this, params Decimal[] values) { return Array.IndexOf(values, @this) != -1; } }