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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:52:27+00:00 2026-05-16T14:52:27+00:00

This is a question for the .NET philosophers: It is my understanding that Microsoft

  • 0

This is a question for the .NET philosophers:

It is my understanding that Microsoft consciously denied use of private classes in C#. Why did they do this and what are their arguments for doing so?

I, for example, am building a large application that includes a reporting tool. This tool uses a lot of business objects that are used only within the reporting tool and not in other parts of the project. I want to encapsulate them for use only within the reporting tool itself.

Great decision is creating separate project in VS for this tool, and I’ll do like that, but I’m interesting, what if I can’t do this – for exmple our architecture wasn`t good enough, and we have big single project.

Behind “private class” I mean a class that can’t be used in any other namespace, except its own.

My question was not – how can I simulate this, or do in another way. I’m just wondering, why not use private keyword with class keyword without any parent classes. I`m thinking there should be some reason, and I want to know it

  • 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-16T14:52:28+00:00Added an answer on May 16, 2026 at 2:52 pm

    There’s a workaround for this, but you might not like it.

    Instead of using a namespace to scope your classes, use a public static partial class:

    Before:

    namespace MyCompany.Foo {
      class Bar { }
      public class Baz { }
    }
    

    After:

    namespace MyCompany {
      public static partial class Foo {
        private class Bar { }
        public class Baz { }
      }
    }
    

    This construct, like a namespace, can span multiple files in the same project. But unlike a namespace, it cannot “escape” from your project (other projects cannot define other members inside Foo).

    There’s an added advantage that you can have utility methods that seem to have no class for code inside Foo.

    The disadvantage is that, to use your non-private classes outside of your fake namespace, you have to reference them inside Foo:

    using MyCompany;
    
    // ...
    
    var baz = new Foo.Baz();
    

    This can be mitigated by using an alias for the class:

    using Baz = MyCompany.Foo.Baz;
    
    // ...
    
    var baz = new Baz();
    

    But you’d have to do it for each non-private class that you want to use.

    UPDATE

    It’s interesting to note that C# 6 will have static using statements, which could effectively improve this proposal to use a public static partial class as a “module”. You would just “use” the “module” to access its types directly.

    Hopefully, it will work like this:

    using MyCompany.Foo;
    
    // ...
    
    var baz = new Baz();
    

    Just as if Foo was a namespace.

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

Sidebar

Related Questions

I just saw this question: Understanding .NET’s SecurityAction parameter for permissions And I have
I already asked this question at the JOS-.NET board but Joel is closing that
This question is pretty much the same as this .Net question exept for java.
This question is directly related to my previous question ASP.NET AJAX Is it possible
Important: This question isn't actually really an ASP.NET question. Anyone who knows anything about
This question relates to an ASP.NET website, originally developed in VS 2005 and now
This question is about a Java JTree or a Window .Net Tree (Winforms) or
(This question specifically in C#, but applies generally to .NET) I have a largish
In this question superwiren asks about the pitfalls for converting a .net 2.0 solution
This question is related to this other question I recently asked... cf.net exception and

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.