나무 숲

TIL / C# Access modifier 본문

Career

TIL / C# Access modifier

wood.forest 2020. 4. 7. 11:27

Public

Can be accessed by any other code in the same assembly or another assembly that references it.

어디에서나 접근 가능!!

alt text

Private

Can only be accessed by code in the same class or struct.

선언된 클래스 또는 구조체 내부에서만 접근 가능

alt text

Protected

Can only be accessed by code in the same class or struct, or in a derived class.

선언된 클래스/구조체 내부, 또는 상속된 클래스에서만 접근 가능

alt text

Private protected (added in C# 7.2)

Can only be accessed by code in the same class or struct, or in a derived class from the same assembly, but not from another assembly.
private outside (the same assembly) protected inside (same assembly)

선언된 클래스/구조체 내, 또는 같은 어셈블리의 상속된 클래스에서 접근 가능

(어셈블리는 dll, exe 등.. 하나의 파일이라고 생각)

alt text

Internal

Can be accessed by any code in the same assembly, but not from another assembly.

같은 어셈블리 내에서 접근 가능

alt text

Protected internal

Can be accessed by any code in the same assembly, or by any derived class in another assembly.
protected outside (the same assembly) internal inside (same assembly)

같은 어셈블리 내, 또는 다른 어셈블리에서 상속된 클래스 내 접근 가능

alt text

Default types

  • internal in class, struct
  • private in class members, struct members

Static

static class

  • 클래스가 인스턴스화 될 수 없다.
  • 클래스의 모든 멤버는 static
  • one-and-only instance of itself

 

https://stackoverflow.com/questions/614818/in-c-what-is-the-difference-between-public-private-protected-and-having-no
https://stackoverflow.com/questions/3763612/default-visibility-for-c-sharp-classes-and-members-fields-methods-etc

728x90
반응형

'Career' 카테고리의 다른 글

TIL / C++ unique  (0) 2020.01.20
gcc 명령어  (0) 2017.07.06
컴퓨터 과학의 주요 분야  (0) 2017.06.16
[C++ STL] vector 튜토리얼 (2) - 함수 Function  (0) 2017.06.07
물리층 - 데이터&신호  (0) 2017.06.06
Comments