Skip to content
Discussion options

You must be logged in to vote

I don't know if I misunderstand you, but that's the matter of a single extension method:

using System.Collections.Generic;

public static class Extensions
{
    public static bool IsIn<T>(this T item, ICollection<T> collection) => collection.Contains(item);
}

If the extension method is in scope, the syntax would be exactly as you mentioned:

int[] myValueArray = { 5, 9, 15 };
if (3.IsIn(myValueArray)) { }

And for IsInAsValued I don't think there is a general answer to how to implement that, so I suppose it would be necessary for you to write it yourself anyway to fulfill your own needs.

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@hrx521
Comment options

Answer selected by hrx521
Comment options

You must be logged in to vote
1 reply
@hrx521
Comment options

Comment options

You must be logged in to vote
1 reply
@hrx521
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants