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

Access Specifier (Chỉ định truy cập) trong C#.NET

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

C# hỗ trợ:

  • Public
  • Private
  • Protected
  • Internal
  • Protected internal

Public

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

Private

Giấu member variables/functions 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 variables/functions 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.