KGy SOFT

ObjectExtensionsInT Method (T, T)

KGy SOFT Core Libraries Help
Gets whether item is among the elements of set.
See the Examples section for an example.

Namespace:  KGySoft.CoreLibraries
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.4.0
Syntax

public static bool In<T>(
	this T item,
	params T[] set
)

Parameters

item
Type: T
The item to search for in set.
set
Type: T
The set of items in which to search the specified item.

Type Parameters

T
The type of item and the set elements.

Return Value

Type: Boolean
 if item is among the elements of set; otherwise, .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks

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.

Examples

C#
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();
    }
}
See Also

Reference