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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:24:32+00:00 2026-06-03T15:24:32+00:00

There are type parameters for methods. Why there are no type parameters for constructors?

  • 0

There are type parameters for methods. Why there are no type parameters for constructors?

Example

I think there are several (not many) examples where it would be usefull. My current problem was following:

internal class ClassA
{
   private readonly Delegate _delegate;

   public ClassA<T>(Func<T> func)
   {
     _delegate = func;
   }
}

A Delegate is enough for my class. But to pass it as method group I need to define the parameter as a Func<T>.

  • 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-03T15:24:34+00:00Added an answer on June 3, 2026 at 3:24 pm

    After reading the C# specification it actually does make sense, but it can be confusing.

    Each class has an associated instance type, and for a generic class declaration the instance type is formed by creating a constructed type from the type declaration, with each of the supplied type arguments being the corresponding type parameter.

    class C<T>
    { 
    }
    

    C<T> is a constructed type, and an instance type will be created by the process of constructing the type using the type parameters.

    C<String> c = new C<String>();
    

    The compiler took the constructed type C<T>, and using the supplied type parameters an instance type of C<String> was created. Generics is only a compile time construct, everything is executed in the terms of closed constructed types at runtime.

    Now let’s take your question and put it to the test here.

    class C
    {
        public C<T>() 
        {
        }
    }
    

    This isn’t possible, because you are trying to construct a type that doesn’t exist.

    C c = new C<String>();
    

    What is the implicit or explicit conversion between C and C<String>? There is none. It doesn’t even make sense.

    Because C is a non-generic type in this example, the instance type is the class declaration itself. So how do you expect C<String> to construct C?

    The proper declaration for what you want to do is this.

    internal class Class<T> 
    {
        private readonly Delegate _delegate;
    
        public Class(Func<T> function) 
        {
            _delegate = function;
        }
    }
    

    Here because we have a constructed type Class<T>, the proper instance type can be created by the compiler.

    Func<String> function = new Func<String>(() => { return String.Empty; });
    Class<String> c = new Class<String>(function);
    

    If you tried to do it the way you want in your question.

    Func<String> function = new Func<String>(() => { return String.Empty; });
    Class c = new Class<String>(function);
    

    The constructed type would be Class<String>, which is not the same as type C, and there is no implicit or explicit conversion from either one. If this was allowed by the compiler, C would be in some unknown and unusable state.

    What you do need to know about constructed types, is this.

    class C<T>
    {
        public C<T>() 
        {
        }
    }
    

    While you cannot explicitly declare a generic constructor, it is valid but only as a closed type constructor at runtime.

    C<String> c = new C<String>();
    

    At compile time, the following constructor is created.

    public C<String>() 
    {
    }
    

    Which is why this is valid:

    C<String> c = new C<String>(); // We just used the closed type constructor
    

    If what you wanted was allowed, something like this could happen.

    class C<T>
    {
        public C<U>() 
        {
        }
    }
    
    // ???
    C<String> c = new C<Int32>();
    

    You can see the problems now that would arise if the construct was allowed. Hopefully this sheds some insight, the specification is rather long and there are many many many sections that cover generics, type parameters, constructed types, closed and open types, bound and unbound.

    It can get very confusing, but its a good thing that this isn’t allowed by the compiler rules.

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

Sidebar

Related Questions

Is there ever a reason to use Type parameters over generics, ie: // this...
When calling methods with type parameters in Scala, I often try to arrange the
Is there any way to store the generic parameter type passed in at construction
Is there an Oracle function to return the data type of the parameter? Alternatively,
Is there some type of cap as to how much CPU an applet can
Why in Boolean type there are two fields with the same value? internal const
I need just dictionary or associative array string => int . There is type
There is some type Record : type Day = Integer type Description = String
Is there a data type in eVC++ that is the equivalent of __int64 ?
Are there any standalone type conversion libraries? I have a data storage system that

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.