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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:13:38+00:00 2026-06-16T20:13:38+00:00

In case the title is not completely self-explanatory, here’s the code that puzzles me:

  • 0

In case the title is not completely self-explanatory, here’s the code that puzzles me:

public interface IFoo<T>
{
}

public class MyClass : IFoo<MyClass.NestedInMyClass>
{
  private class NestedInMyClass
  {
  }
}

I’m suprised this compiles with no error. It feels like I’m exposing a private type. Shouldn’t this be illegal?

Maybe your answers will simply be “There’s no rule against that, so why wouldn’t it be OK?” Perhaps it’s equally surprising that MyClass.NestedInMyClass is even in “scope”. If I remove the MyClass. qualification, it will not compile.

(If I change IFoo<> into a generic class, which should then become base class of MyClass, this is illegal, for a base type must be at least as accessible as the type itself.)

I tried this with the C# 4 compiler of Visual Studio 2010.

  • 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-16T20:13:39+00:00Added an answer on June 16, 2026 at 8:13 pm

    No external code can cast the object to this interface, so it’s not an accessibility issue.

    public classes are even allowed to implement private or internal interfaces – and similarly, no cast can actually occur from external code.

    Re: discussion about implementations that depend on T – you’ll be allowed it if you use explicit interface implementation – because the methods for the interface are effectively private in that case. E.g.:

    public interface IFoo<T>
    {
      void DoStuff(T value);
    }
    
    public class MyClass : IFoo<MyClass.NestedInMyClass>
    {
      void IFoo<MyClass.NestedInMyClass>.DoStuff(MyClass.NestedInMyClass value)
      {
      }
      private class NestedInMyClass
      {
      }
    }
    

    works (because the interface implementing method isn’t exposed by the class itself).

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

Sidebar

Related Questions

The following code looks at any element with the title-case class and modifies the
If that title did not make sense (which I'm expecting =)) here is what
NSString *part = self.navigationItem.title; if (part == @Case) { NSLog(@title: %@, part); } and
There are many ways to Title Case in java . But how do you
Case One Say you have a little class: class Point3D { private: float x,y,z;
Case i'm trying to write a GWTTestCase for a certain class, used as a
Case with bootstrap: Example code function( $ ){ }( window.jQuery );
I have an ajax form within a parent html form (not my code!). The
I think the title for this question is probably wrong, but I'm not sure
As the title says I want to transfer data, in this case the information

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.