Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Mục đích của Access Specifier (Chỉ định truy cập) trong C#

Để định nghĩa scope và visibility của class member, dùng access specifier.

C# hỗ trợ 5 access specifier:

  • Public
  • Private
  • Protected
  • Internal
  • Protected internal

Public

Cho phép class expose member variables/functions ra functions/objects khác.

Private

Giấu member khỏi functions/objects khác. Chỉ functions cùng class truy cập được.

Protected

Cho phép child class truy cập member của base class.

Internal

Cho phép expose member trong current assembly.

Protected Internal

Giấu member khỏi class objects/functions khác, trừ child class trong cùng application.