Note
If elements of set are complex expressions consider to use the InT(T, FuncT) overload instead to prevent evaluating all elements until they are actually compared.
public static bool In<T>(
this T item,
params T[]? set
)
<ExtensionAttribute>
Public Shared Function In(Of T) (
item As T,
ParamArray set As T()
) As Boolean
public:
[ExtensionAttribute]
generic<typename T>
static bool In(
T item,
... array<T>^ set
)
[<ExtensionAttribute>]
static member In :
item : 'T *
set : 'T[] -> bool
This method works similarly to the in operator in SQL and Pascal.
This overload uses generic IEqualityComparerT implementations to compare the items for the best performance.
using System;
using KGySoft.CoreLibraries;
public class Example
{
public static void Main()
{
string stringValue = "blah";
// standard way:
if (stringValue == "something" || stringValue == "something else" || stringValue == "maybe some other value" || stringValue == "or...")
DoSomething();
// In method:
if (stringValue.In("something", "something else", "maybe some other value", "or..."))
DoSomething();
}
}