String - In
A T extension method to determines whether the object is equal to any of the provided values.
public static void Main() { string [] values = {"EntityFramework", " ", "SQL", "", "Java", null}; string newValue = "EntityFramework"; // C# Extension Method: String - In if(newValue.In(values)) { Console.WriteLine("String: {0}", newValue); } }
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> public static bool In(this String @this, params String[] values) { return Array.IndexOf(values, @this) != -1; } }