Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7009351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:51:04+00:00 2026-05-27T21:51:04+00:00

class Sample { public static T M<T, TParam1>(TParam1 param1) { return default(T); } }

  • 0
class Sample
{
    public static T M<T, TParam1>(TParam1 param1)
    {
        return default(T);
    }
}
class Program
{
    static void Main(string[] args)
    {

        double d = Sample.M((int)121);
    }
}

This code doesn’t compile and results in the following error message:

The type arguments for method
‘ThreadPoolTest.Sample.M(TParam1)’ cannot be inferred from
the usage. Try specifying the type arguments
explicitly

Why isn’t type inference working in this example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:51:04+00:00Added an answer on May 27, 2026 at 9:51 pm

    Type inference can only use the arguments to the method call. The fact that you’re assigning the result to a double is entirely irrelevant as far as type inference is concerned. In other words, as far as the compiler is concerned, it needs to work out what this means:

    Sample.M((int) 121)
    

    without any more information. For example, you could mean Sample.M<int, int>, or Sample.M<double, int>, or Sample.M<string, int> – there’s no information so say which of those is a better match.

    You don’t mention T in the parameter list, so type inference can’t help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Sample { public static void main(String[] args) { int year = 2012;
Given the following sample: public class Main { public static void main(String[] args) {
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
Here is a sample code: public class TestIO{ public static void main(String[] str){ TestIO
Given the code below: class Sample { public static void Run() { int i
public class Sample{ private const =constant string; public static object StaticMethod(args){ var result= SomeOtherClass.StaticMethod(const,args);
I created a non-static inner class like this: class Sample { public void sam()
Given the following code sample: public class WeirdStuff { public static int doSomething() {
I provide my sample: class a { public: static int m_n; static int memfuc();
Sample code : public class CA { public CA(string s, List<int> numList) { //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.