今天记录下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