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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:38:51+00:00 2026-06-06T07:38:51+00:00

So I have a class with a wrapper class inside like so: public class

  • 0

So I have a class with a wrapper class inside like so:

public class RandomClass<TK, TV>
{
    internal class RandomClassWrapper<TK, TV> : RandomClass<TK, TV> {}
}

Now the reason for this is, that RandomClassWrapper is using the new keyword, to override the behaviour of some of the methods in RandomClass. This is because I only want my library to be able to access these functions.

It also needs to modify some of the private variables in RandomClass, which is why it is nested.

However, When I want to initialize this, I have to go

var rc = new RandomClass<int, int>.RandomClassWrapper<int, int>();

Why is that first <int, int> required? Why couldn’t it just be wrote like this:

var rc = new RandomClass.RandomClassWrapper<int, int>();

Is there any way that I can avoid having to type that extra <int, int> which can turn into things like: <Dictionary<string, nameofclass>, List<thisistoolong>>

That is an exaggeration, but you understand what I mean. Having to put those types twice is a huge waste of space.

Can anyone suggest a different approach?

Since this helps to clear up the question a bit, I’ll bring attention to these two comments:

So, is your question "why can’t the compiler infer the generic arguments to RandomClassWrapper from the arguments to RandomClass? – Ed S. 3 mins ago

@EdS. That is one component of the question, yes. The other, is: Since it can’t, is there an alternate approach / hack that can clean this up and avoid having to type the generic arguments twice. – caesay just now

  • 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-06T07:38:53+00:00Added an answer on June 6, 2026 at 7:38 am

    The second class is nested within the outer generic class, so there’s no need for the type respecification.

    internal class RandomClassWrapper : RandomClass<TK, TV> {}
    

    Should compile correctly, then you just need to specify one set of generics, as the nested class automatically shares the types:

    var rc = new RandomClass<int, int>.RandomClassWrapper();
    

    What you need to realize is that under the hood, new class definitions are generated by the compiler for each different set of generic types (poor wording, I think). This means that

    RandomClass<int, int> is already a different definition to RandomClass<string, string> and thus its internal nested class is also already contained within a seperate generic definition.

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

Sidebar

Related Questions

I have something like this: <div class=wrapper> <div class=drag object1>Example1</div> <div class=drag object1>Example1</div> <div
I have a class A that looks like this: class A { // A's
I have this simple html: <div class=wrapper> <span class=higher> [higher] <span class=lower> hello </span>
Let's say I have objects which look very roughly like this: class object {
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I
With predetermined class structure like this: @XmlRootElement class Root { Foo property; transient Wrapper
I have a working wrapper class for Dallmeier camera devices, It contains a callback
I have a class written in c# which is acting as a wrapper around
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
I have class A: public B { ...} vector<A*> v; I want to do

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.