- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are nested classes in C#?
A nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.
Let us see an example code snippet of nested classes in C# −
class One { public int num1; public class Two { public int num2; } } class Demo { static void Main() { One a = new One(); a.num1++; One.Two ab = new One.Two(); ab.num2++; } }
The example shows that class Two is a nested class. Class Two is enclosed inside the class One declaration.
The class Two here is enclosed inside the declaration of class One. Class Two is thus a nested class. Because it has a public accessibility modifier, it can be accessed in places other than class One's scope.
- Related Articles
- Nested Classes in C++
- Nested Classes in C#
- C# Nested Classes
- What are the different types of nested classes are defined in Java?
- Nested Classes in Java
- Static Nested Classes in Java
- What are abstract classes in C#?
- What are the classes in C#?
- What are collection classes in C#?
- What are nested namespaces in C#?
- What are I/O classes in C#?
- What are nested structures in C language?
- What are Base and Derived Classes in C#?
- What are storage classes of variables in C++?
- What are the rules for naming classes in C#?

Advertisements