C# 类(6) 访问限制

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    // 访问限制.
    #region 自定义类
    class MyClass
    {
        private void ShowMessage()  // 私有方法, 关键字 Private  . 这是也是默认的.
        { Console.WriteLine("私有的,不能在类的外部被访问"); }

        public void SHowMessage()  //公有方法, 关键字 Public
        { Console.WriteLine("公有的,可以在任何地方被访问"); }

        protected void Showmessage()  //受保护的方法, 子类可以访问. 关键字 Protected
        { Console.WriteLine("子类可以访问"); }

        internal void SHOwMessage()  //当前单元可以任意访问.
        { Console.WriteLine("当前单元可以任意访问"); }
    }
    #endregion
    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}
原文地址:https://www.cnblogs.com/mdnx/p/2707226.html