Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!