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 7711551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:24:17+00:00 2026-06-01T01:24:17+00:00

When I declare a method like this: void DoWork<T>(T a) { } void DoWork(int

  • 0

When I declare a method like this:

void DoWork<T>(T a) { }
void DoWork(int a) { }

And call it with this:

int a = 1;
DoWork(a);

What DoWork method will it call and why? I can’t seem to find it in any MSDN documentation.

  • 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-06-01T01:24:18+00:00Added an answer on June 1, 2026 at 1:24 am

    As Eric Lippert says:

    The C# specification says that when you have a choice between calling ReallyDoIt<string>(string) and ReallyDoIt(string) – that is, when the choice is between two methods that have identical signatures, but one gets that signature via generic substitution – then we pick the “natural” signature over the “substituted” signature.

    UPDATE:

    What we have in C# spec (7.5.3):

    When a generic method is called without specifying type arguments, a type inference process attempts to infer type arguments for the call. Through type inference, the type argument int is determined from the argument to the method. Type inference occurs as part of the binding-time processing of a method invocation and takes place before the overload resolution step of the invocation.

    When a particular method group is specified in a method invocation, and no type arguments are specified as part of the method invocation, type inference is applied to each generic method in the method group. If type inference succeeds, then the inferred type arguments are used to determine the types of arguments for subsequent overload resolution. If overload resolution chooses a generic method as the one to invoke, then the inferred type arguments are used as the actual type arguments for the invocation. If type inference for a particular method fails, that method does not participate in overload resolution.

    So before overload resolution we have two methods in method group. One DoWork(int) and other inferred DoWork<int>(int).

    And we go to 7.5.3.2 (Better function member):

    In case the parameter type sequences {P1, P2, …, PN} and {Q1, Q2, …, QN} are equivalent (i.e. each Pi has an identity conversion to the corresponding Qi), the following tie-breaking rules are applied, in order, to determine the better function member.
    1) If MP is a non-generic method and MQ is a generic method, then MP is better than MQ.

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

Sidebar

Related Questions

I'm trying to declare a method in main.h like this: void buildGraph(int gNum, Graph**
In ActionScript 3 you can declare optional parameters like this: function (i:int = 0,
How can I declare a method with keyword arguments just like rails do. some
If I have a method declared like this: private void someFunction(object[] param1) When I
I've written a method that I'd like to declare as const, but the compiler
In C#, how can I declare a method in an interface to return an
How i can declare a global method in delphi prism using the __Global class?
How do you declare an Objective-C static method that can be called without a
Let's suppose I have a struct like this: struct my_struct { int a; int
I typically have code like this on a form: private void PerformLongRunningOperation() { BackgroundWorker

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.