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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:35:36+00:00 2026-05-11T02:35:36+00:00

I am relatively new to C# and each time I begin to work on

  • 0

I am relatively new to C# and each time I begin to work on a C# project (I only worked on nearly mature projects in C#) I wonder why there are no inner classes?

Maybe I don’t understand their goal. To me, inner classes — at least private inner classes — look a lot like ‘inner procedures’ in Pascal / Modula-2 / Ada : they allow to break down a main class in smaller parts in order to ease the understanding.

Example : here is what is see most of the time :

public class ClassA {    public MethodA()    {       <some code>       myObjectClassB.DoSomething(); // ClassB is only used by ClassA       <some code>    } }  public class ClassB {    public DoSomething()    {    } } 

Since ClassB will be used (at least for a while) only by ClassA, my guess is that this code would be better expressed as follow :

   public class ClassA    {       public MethodA()       {          <some code>          myObjectClassB.DoSomething(); // Class B is only usable by ClassA          <some code>       }        private class ClassB       {          public DoSomething()          {          }       }    } 

I would be glad to hear from you on this subject – Am I right?

  • 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. 2026-05-11T02:35:37+00:00Added an answer on May 11, 2026 at 2:35 am

    Nested classes (probably best to avoid the word ‘inner’ as nested classes in C# are somewhat different to inner classes in Java) can indeed be very useful.

    One pattern which hasn’t been mentioned is the ‘better enum’ pattern – which can be even more flexible than the one in Java:

    public abstract class MyCleverEnum {     public static readonly MyCleverEnum First = new FirstCleverEnum();     public static readonly MyCleverEnum Second = new SecondCleverEnum();      // Can only be called by this type *and nested types*     private MyCleverEnum()     {     }      public abstract void SomeMethod();     public abstract void AnotherMethod();      private class FirstCleverEnum : MyCleverEnum     {         public override void SomeMethod()         {              // First-specific behaviour here         }          public override void AnotherMethod()         {              // First-specific behaviour here         }     }      private class SecondCleverEnum : MyCleverEnum     {         public override void SomeMethod()         {              // Second-specific behaviour here         }          public override void AnotherMethod()         {              // Second-specific behaviour here         }     } } 

    We could do with some language support to do some of this automatically – and there are lots of options I haven’t shown here, like not actually using a nested class for all of the values, or using the same nested class for multiple values, but giving them different constructor parameters. But basically, the fact that the nested class can call the private constructor gives a lot of power.

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

Sidebar

Related Questions

I'm relatively new to J2ME and about to begin my first serious project. My
I'm a relatively new hire, and I'm starting on a small, fairly simple project.
So I am a first time user here, and still relatively new to SQL.
I'm relatively new to django.. In the app that I'm building, there are multiple
Relatively new to rails and trying to model a very simple family tree with
Being relatively new to the .net game, I was wondering, has anyone had any
Being relatively new to functional programming, I expend lots of energy wondering is this
Caveat: I'm relatively new to coding as well as TextMate , so apologies if
I am relatively new to web services and am wondering what the standard best
I'm relatively new to web application programming so I hope this question isn't too

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.