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

In

Determines whether a IEnumerable<T> contains a specific value

Source

public static bool In<T>(this T value, IEnumerable<T> values)
{
	if(values == null)
		throw new ArgumentNullException("values");

	return values.Contains(value);
}

Example

int[] numbers = {1, 2, 3, 4 };
int a = 3;

if(a.In(numbers))
{ ... }

Author: Lucas

Submitted on: 7 mrt. 2008

Language: C#

Type: System.Object

Views: 4802