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

In

Returns true when a number is included in the specified collection.

Source

public static bool In(this int number, params int[] collection)
{
	bool isIn = false;

	foreach(var i in collection)
	{
		if(number == i)
		{
			isIn = true;
			break;
		}
	}

	return isIn;
}

Example

int a = SomePlace.A;

if(a.In(2, 4))
 DoSomething();
else
 DoSomethingElse();

Author: Victor Rodrigues

Submitted on: 13 mei 2009

Language: C#

Type: System.Int32

Views: 4895