Add information about access modifiers (#24422)
* Add information about access modifiers Added some information about 3 most common access modifiers and a simple example. * Fix indent
This commit is contained in:
committed by
The Coding Aviator
parent
20735a30cd
commit
c910a1efad
28
guide/english/csharp/access-modifiers/index.md
Normal file
28
guide/english/csharp/access-modifiers/index.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: Access modifiers
|
||||||
|
---
|
||||||
|
|
||||||
|
# Access modifiers
|
||||||
|
|
||||||
|
Access modifiers are keywords used to specify the declared accessibility of a member or a type.
|
||||||
|
|
||||||
|
Here are the 3 most common access modifiers:
|
||||||
|
* `public` - access is not restricted.
|
||||||
|
* `protected` - access is limited to the containing class or types derived from the containing class.
|
||||||
|
* `private` - access is limited to the containing type.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
```csharp
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
public string FirstName { get; set;} // these can be accessed from anywhere
|
||||||
|
public string LastName { get; set;}
|
||||||
|
|
||||||
|
protected string SecretMessage { get; set;} // this can be accessed from this class or any derived classes
|
||||||
|
|
||||||
|
private int PersonId { get; set;} // this can only be accessed from this class
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
- [Microsoft](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/access-modifiers)
|
Reference in New Issue
Block a user