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

  • Home
  • SEARCH
  • 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 8769269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:17:51+00:00 2026-06-13T17:17:51+00:00

Assuming this: public class GenericMethods { public T Method<T>() where T : struct {

  • 0

Assuming this:

public class GenericMethods
{
    public T Method<T>() where T : struct
    {
        // Do something specific to a struct
    }

    public T Method<T>() where T : class
    {
        // Do something specific to a class
    }
}

Is somehow invalid at compile time, because the two method take the same parameters. But would there really be a moment that the two methods would collide since the constraints are mutually exclusive? Would it be possible while resolving T that the software would be unable to choose one of the two methods?

How would someone make two generic methods of the same name and parameters that would differ if the generic type is a struct or a class?

  • 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-13T17:17:53+00:00Added an answer on June 13, 2026 at 5:17 pm

    No. Contraints are not taken into account. Neither are return types. This will not compile, and is not legal C#.

    This is documented in 3.6 of the C# language spec:

    The signature of a method specifically does not include the return type, the params modifier that may be specified for the right-most parameter, nor the optional type parameter constraints.

    While the two methods are “logically” distinct, and couldn’t conflict, as the constraints should make it clear which is being called, the C# language doesn’t support this. The language designers decided that this was the way they chose to implement the rules for C#.

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

Sidebar

Related Questions

Assuming I have a simple structure that looks like this: public class Range {
Lets say I have a two classes like this: public class LocalResources { public
Assuming that I have objects similar to this: public class User { public int
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a
Assuming that I cannot run something like this with Fabric: run(svn update --password 'password'
Is this good OO Design assuming you want every inheriting class to be a
Like this: public class remoteStatusCounts : RemoteStatus { public int statusCount; public remoteStatusCounts(RemoteStatus r)
In java, I have a class like this: public class MyClass extends Properties {
I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have two classes an Arc class and a Line class public class Arc

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.