2

So the problem is following: I'm trying to somehow differentiate between two same methods while calling them. Idea is if I pass IEnumerable<> it should call respective method taking IEnumerable rather than just T. But in reality every time first method taken T get called. Is there any workaround for it?

    public void TestMethod<T>(T value)
    {

    }

    public void TestMethod<T>(IEnumerable<T> values)
    {

    }

Or if it's impossible maybe somehow to cast T from first method to IEnumerable, I've tried doing it with expressions but no luck still..

IRCodder
  • 41
  • 4
  • There is no way to do that AFAIK. The first method always matches because it is completely open (there are no type constraints). There is no such thing as "the best match" when determining which method to use at runtime. – Igor Mar 17 '22 at 19:41

0 Answers0