Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do we use a nested class in C# [duplicate]

Would like to know when it is right to uses a nested classes in C#? Do we have incidents in which the use of it is unjustified and therefore not correct?

If you can give examples for both situations Thanks

like image 526
Mulder Avatar asked Dec 21 '22 16:12

Mulder


2 Answers

I find it's convenient to use a nested class when you need to encapsulate a format of data that is primarily going to be used within the parent class. This is usually because the purpose or format of the data is so bespoke to the parent class that it's not really suitable for wider use within your solution.

like image 112
Brian Scott Avatar answered Dec 25 '22 22:12

Brian Scott


Here's a simple basic introduction to nested classes.

Nested_Classes

like image 45
MattC Avatar answered Dec 25 '22 23:12

MattC