C# adds a FOURTH access level — internal (accessible within the same assembly, not across assemblies) — that has no direct C++ equivalent, since "assembly" is a .NET-specific compiled-unit concept C++'s translation-unit/library model doesn't share; meanwhile public/private/protected carry the same meanings as C++, and the default-to-private-when-unspecified rule for class members is IDENTICAL to what Topic_CPP already confirmed for C++ classes — making internal (plus the two combinations protected internal and private protected, mentioned but deferred) the one genuinely new addition in this chapter. [S1]
🧠 핵심 개념 (Core concepts)
public — accessible from ALL classes. [S1]
private — accessible ONLY within the same class. [S1]
protected — accessible within the same class OR classes that inherit from it (full detail deferred to Inheritance). [S1]
internal — accessible only within its own ASSEMBLY, not from another assembly (detail deferred; no equivalent concept in C/C++ covered so far in this series). [S1]
Combined modifiers — protected internal and private protected exist but aren't covered in depth here. [S1]
Default access = private — if no access modifier is specified on a class member, it defaults to private. [S1]
Purpose — controls visibility/security of class members, and enables Encapsulation (hiding sensitive data by making fields private, deferred to the next chapter). [S1]
📖 세부 내용 (Details)
Private field, accessed from WITHIN its own class: works fine, prints "Mustang". [S1]
Private field, accessed from a DIFFERENT class (Program): compile error — 'Car.model' is inaccessible due to its protection level. [S1]
Public field, accessed from a different class: works, prints "Mustang". [S1]
Implicit private default: class Car { string model; string year; } — both fields are private even though no keyword is written. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
기본 접근 수준(private)은 C++와 동일: 접근 제한자를 명시하지 않으면 private가 기본값이라는 규칙이 Topic_CPP의 Access Specifiers 챕터에서 확인된 규칙과 차이가 없다는 점이 확인됨. [S1]
internal은 C/C++에 대응 개념이 없는 새로운 접근 수준: "같은 어셈블리 내에서만 접근 가능, 다른 어셈블리에서는 불가"라는 internal의 정의는 .NET의 컴파일 단위인 어셈블리 개념에 의존하며, 이 시리즈의 C/C++ 챕터에는 대응하는 개념이 없었다는 점이 새로운 차이로 확인됨. [S1]
🛠️ 적용 사례 (Applied in summary)
private 필드를 같은 클래스 안에서 접근할 때는 성공하고, 다른 클래스(Program)에서 접근하면 컴파일 에러가 나는 것을 대비해 보여주는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
💻 코드 패턴 (Code patterns)
private field inaccessible from another class — compile error (C#):
classCar{privatestringmodel="Mustang";}classProgram{staticvoidMain(string[]args){CarmyObj=newCar();Console.WriteLine(myObj.model);// Error: 'Car.model' is inaccessible due to its protection level}}
✅ 검증 상태 및 신뢰도
상태: draft
검증 단계: conceptual
출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)