C#修饰class的关键字使用

今天记录下c# 修饰class 的一些关键字的一些用法,不多说,每天记录笔记:

对应的代码,这里使用了接口,因为c#不支持c++中的多重继承,可以使用继承接口的形式达到多重继承的目的:

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

namespace Chart
{
    //abstract 类只能在当前项目中访问,不能实例化,只能被继承
    public abstract class MyBase
    {

    }
    // internal 类只能在当前项目中访问
    internal class MyClass : MyBase
    {

    }
    //interface  接口可以外部访问
    public interface IMyBaseInterface
    {

    }
    // internal interface 当前工程使用的接口
    internal interface IMyBaseInterface2
    {

    }
    //继承接口
    internal interface IMyInterface : IMyBaseInterface , IMyBaseInterface2
    {

    }
    //internal sealed 只能在当前项目里使用,不能被继承,只能实例化
    internal sealed class myComplexClass : MyBase, IMyInterface
    {

    }


    class Program
    {
        static void Main(string[] args)
        {
            myComplexClass myObj = new myComplexClass();
            Console.WriteLine(myObj.ToString());
            Console.ReadKey();
        }
    }
}

 输出结果:

Chart.myComplexClass

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值