Favicon

Access modifiers

Peponi12/1/20243m

C#
SyntaxKeywordModifier

1. Introduction

Access Modifiers (액세스 한정자) 는 형식 또는 멤버의 접근성을 지정할 때 사용한다. C#에 있는 한정자는 총 5가지로 이를 조합하여 7가지의 접근성 수준을 지정할 수 있다.

2. 액세스 한정자

C#에 있는 액세스 한정자는 아래와 같다.

항목비고
public
protected
internal
private
fileC# 11 (.NET 7)

이를 이용하여 지정할 수 있는 접근성 수준은 아래와 같다.

항목접근성 범위비고
public제한 없음
protected파생된 형식
internal선언 어셈블리
private선언 형식
file코드 파일 단위C# 11 (.NET 7)
protected internal선언 어셈블리 또는 파생된 형식
private protected선언 어셈블리 안의 파생된 형식C# 7.2

상기 표의 2 항목 (protected internal, private protected) 의 경우 의미가 모호하게 보일 수 있다. 특히 private protected가 그럴 수 있는데, 이는 private 단어 때문이다.

2.1. protected internal, private protected

Protected internal and private protected

모호한 두 요소 (protected internal, private protected) 에 대한 설명을 위해 다이어그램을 하나 그렸다. public+, protected internal#~, private protected-#로 표시하였으며 접근 가능 여부를 함께 넣었다.

결론적으로 보면, 접근성 범위를 아래와 같이 정리할 수 있다.

  • protected internal : internal + protected
  • private protected : protectedinternal로 제한

따라서 private protected에서 private이란 단어는 Assembly 내부 정도로 해석할 수 있다. internal protected가 맞는 단어 접근인 것 같은데, protected internalinternal protected와 혼용되고 있어 용어를 따로 설정한 것 같다.

자세한 내용은 protected internal, private protected에서 다루도록 한다.

3. 참조 자료