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

IsNotIn

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

Source

public static bool IsNotIn<T>(this T keyObject, IEnumerable<T> collection)
{
    return keyObject.IsIn(collection) == false;
}

Example

var exceptionList = new List<string> { "exception1", "exception2" };
var query = myEntities.MyEntity
.Select(e => e.Name)
.Where(e => e.IsNotIn(exceptionList));

Author: Joan Comas

Submitted on: 20 apr 2016

Language: C#

Type: Generic

Views: 3989