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


Determines if an instance is contained in a sequence. Is the equivalent of Contains, but allows a more fluent reading "if item is in list", specially useful in LINQ extension methods like Where


public static bool IsIn<T>(this T keyObject, IEnumerable<T> collection)
    return collection.Contains(keyObject);


var inclusionList = new List<string> { "inclusion1", "inclusion2" };
var query = myEntities.MyEntity
.Select(e => e.Name)
.Where(e => e.IsIn(inclusionList));

Author: Joan Comas

Submitted on: 20 apr 2016

Language: C#

Type: Generic

Views: 9857