In C#, what is the difference between public, private, protected, and having no access modifier?

前端 未结 16 2979
盖世英雄少女心
盖世英雄少女心 2020-11-22 01:12

All my college years I have been using public, and would like to know the difference between public, private, and protected

16条回答
  •  春和景丽
    2020-11-22 02:03

    Yet another visual approach of the current access modifier (C# 7.2). Hopefully the schema helps to remember it easier
    (click the image for interactive view.)

    Outside Inside

    If you struggle to remember the two-worded access modifiers, remember outside-inside.

    • private protected: private outside (the same assembly) protected inside (same assembly)
    • protected internal: protected outside (the same assembly) internal inside (same assembly)

提交回复
热议问题