Object - In
A T extension method to determines whether the object is equal to any of the provided values.
public static void Main() { int searchVal = -1277; // C# Extension Method: Object - In Display(searchVal, searchVal.In(32767, 235, 0, -1277, -32767)); Display(searchVal, searchVal.In(32767, 235, 0, -1278, -32767)); } public static void Display(object searchVal, bool status) { if(status) { Console.WriteLine("{0} is in the list.", searchVal); } else { Console.WriteLine("{0} is not 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> /// <typeparam name="T">Generic type parameter.</typeparam> /// <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> public static bool In<T>(this T @this, params T[] values) { return Array.IndexOf(values, @this) != -1; } }