Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi. I wanna ask you people here what is the point of using nested classes ?

What I have tried:

Asking a question here in CodeProject.com
Posted
Updated 29-May-17 1:53am
Comments
[no name] 29-May-17 7:45am    
https://www.bing.com/search?q=c%23+nested+classes
Maciej Los 29-May-17 7:45am    
Not a question at all!
It sounds similar to: What's the point of using screwdriver?

What's the point to ask all these questions here?
Go and fetch a good book - or better a course and start learning...
 
Share this answer
 
They can help provide "hidden" classes:
C#
public class MyClass
   {
   private class MyNestedClass
      {
      public MyNestedClass()
         {
         }
      }
    public void AMethod()
        {
        MyNestedClass mnc = new MyNestedClass();
        }
   }
Only MyClass can create instances of MyNestedClass - or indeed see it - classes outside don't even know it's there.

They can also help to "group" classes which might have common names together into the "umbrella" of the containing class. That way, you have to use the fully qualified class name to use it and it doesn't conflict with any other class name:
    public void MyMethod()
        {
        MyClass.MyNestedClass mnc = new MyClass.MyNestedClass();
        }
    }
public class MyClass
    {
    public class MyNestedClass
        {
        public MyNestedClass()
            {
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900