Private Access Modifier in C# with Example

Private Access Modifier in C# with Example
Rating: 5 - 1 Votes

Private Access Modifier in C# with Example

C#Private access modifier in C# is only used when you want to use some type member within the containing type only and want to restrict it from accessing outside of the containing type.  All type members are by default Private, so it is not necessary to use Private keyword in front of them.  But it’s a good habit to to use it because it will make your code more readable and easy to understand.

To initialize a Private type member, you can make use of custom constructor with parameters or properties.  An example for Private access modifier in C# is given below.

 Output:

Robert Marks
Press any key to continue . . .