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

365
Visualizações
The type arguments for method The type arguments for method `System.MemoryExtensions.Reverse<T>(this System.Span<T>)' cannot be inferred from the usag

Why does my code come up with this error? I'm trying to solve the second question on Coderbyte, it's about reversing a string.

Error:

Main.cs(8,39): error CS0411: The type arguments for method `System.MemoryExtensions.Reverse<T>(this System.Span<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly

Code:

using System;

class MainClass {

  public static string FirstReverse(string str) {

    
    string backwards = new string(str.Reverse().ToArray());
    return backwards;
  }

  static void Main() {  
    Console.WriteLine(FirstReverse(Console.ReadLine()));
  } 

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

0

String (https://docs.microsoft.com/en-us/dotnet/api/system.string?view=net-5.0) does not have a method Reverse, so the only thing to resolve Reverse to is a static extension method available with the using directives in your program. From System the best the compiler could do is System.MemoryExtensions.Reverse<T>(this System.Span<T>) but it couldn't use this because String is not a Span<T> for any T.

You were probably looking for Enumerable.Reverse<T> (https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.reverse?view=net-5.0) because String is an IEnumerable<char>. To use this you will need to include it with using System.Linq;

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