Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Reflection in .NET
class Program
{
    static void Main(string[] args)
    {
        Type doub = typeof(Doub);
        object result = doub.InvokeMember("Call", BindingFlags.InvokeMethod, null, null, new object[] { });
    }
}

public class Doub
{
    public Collection<string> Call()
    {
        Collection<string> collection = new Collection<string>();
        return collection;
    }

    public Collection<T> Call<T>()
    {
        Collection<T> collection = new Collection<T>();
        return collection;
    }
}

I tried to call the Call method, but the program cannot figure out which method to call. Error: (System.Reflection.AmbiguousMatchException: "Ambiguous match found). How can you call exactly the Call() method of the class?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to use a different way to get the method to execute. For example, the Type object has a method called GetMethod with various overloads, you could use the one that allows you to specify how many generic parameters the method has, for example:

Type doub = typeof(Doub);
var callMethod = doub.GetMethod("Call", 0, new Type[] {});

// You need an instance of the object to call the method on
var x = new Doub();

var result = callMethod.Invoke(x, new object[] {});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda