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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:56:37+00:00 2026-05-16T18:56:37+00:00

Method overloading allows us to define many methods with the same name but with

  • 0

Method overloading allows us to define many methods with the same name but with a different set of parameters ( thus with the same name but different signature ).

Are these two methods overloaded?

class A
{
    public static void MyMethod<T>(T myVal) { }
    public static void MyMethod(int myVal) { }
}

EDIT:

Shouldn’t statement A<int>.MyMethod(myInt); throw an error, since constructed type A<int> has two methods with the same name and same signature?

  • 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-16T18:56:37+00:00Added an answer on May 16, 2026 at 6:56 pm

    Are the two methods overloaded?

    Yes.

    Shouldn’t statement A<int>.MyMethod(myInt); throw an error, since constructed type A<int> has two methods with the same signature?

    The question doesn’t make sense; A is not a generic type as you have declared it. Perhaps you meant to ask:

    Should the statement A.MyMethod(myInt); cause the compiler to report an error, since there are two ambiguous candidate methods?

    No. As others have said, overload resolution prefers the non-generic version in this case. See below for more details.

    Or perhaps you meant to ask:

    Should the declaration of type A be illegal in the first place, since in some sense it has two methods with the same signature, MyMethod and MyMethod<int>?

    No. The type A is perfectly legal. The generic arity is part of the signature. So there are not two methods with the same signature because the first has generic arity zero, the second has generic arity one.

    Or perhaps you meant to ask:

    class G<T> 
    {
        public static void M(T t) {}
        public static void M(int t) {}
    }
    

    Generic type G<T> can be constructed such that it has two methods with the same signature. Is it legal to declare such a type?

    Yes, it is legal to declare such a type. It is usually a bad idea, but it is legal.

    You might then retort:

    But my copy of the C# 2.0 specification as published by Addison-Wesley states on page 479 "Two function members declared with the same names … must have have parameter types such that no closed constructed type could have two members with the same name and signature." What’s up with that?

    When C# 2.0 was originally designed that was the plan. However, then the designers realized that this desirable pattern would be made illegal:

    class C<T> 
    {
        public C(T t) { ... } // Create a C<T> from a given T
        public C(Stream s) { ... } // Deserialize a C<T> from disk
    }
    

    And now we say sorry buddy, because you could say C<Stream>, causing two constructors to unify, the whole class is illegal. That would be unfortunate. Obviously it is unlikely that anyone will ever construct this thing with Stream as the type parameter!

    Unfortunately, the spec went to press before the text was updated to the final version. The rule on page 479 is not what we implemented.

    Continuing to pose some more questions on your behalf:

    So what happens if you call G<int>.M(123) or, in the original example, if you call A.MyMethod(123)?

    When overload resolution is faced with two methods that have identical signatures due to generic construction then the one that is generic construction is considered to be "less specific" than the one that is "natural". A less specific method loses to a more specific method.

    So why is it a bad idea, if overload resolution works?

    The situation with A.MyMethod isn’t too bad; it is usually pretty easy to unambiguously work out which method is intended. But the situation with G<int>.M(123) is far worse. The CLR rules make this sort of situation "implementation defined behaviour" and therefore any old thing can happen. Technically, the CLR could refuse to verify a program that constructs type G<int>. Or it could crash. In point of fact it does neither; it does the best it can with the bad situation.

    Are there any examples of this sort of type construction causing truly implementation-defined behaviour?

    Yes. See these articles for details:

    https://ericlippert.com/2006/04/05/odious-ambiguous-overloads-part-one/

    https://ericlippert.com/2006/04/06/odious-ambiguous-overloads-part-two/

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

Sidebar

Related Questions

I have problem with ActionResult Method overloading in MVC2 I have 3 methods public
Instead of supporting method overloading Ruby overwrites existing methods. Can anyone explain why the
Objective-C doesn't support methods overloading. Why? Is it doable but Apple decided not implement
PHP object overloading is explained here . Basically it allows you to define some
I've done plenty of Method Overloading, but now I have an instance where I
I want to use overloading feature in Ruby like many other languages, but Ruby
I have one doubt concerning c# method overloading and call resolution. Let's suppose I
Why return type of a method is not considered in method overloading ? Can
I have a long standing doubt. Could someone please tell me whether method overloading
Method chaining is the practice of object methods returning the object itself in order

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.