编辑:我道歉,我的意思是protected代替restricted.我累了
是否有相当于Java restricted和extendsC#的?我可以看到它们都不在C#中,它们对当前的编程项目很有用.
码:
using System;
namespace CServer.API
{
public class Plugin
{
restricted Plugin ()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
并说一个插件这样做:
using System;
using CServer.API;
namespace Whatever
{
public class WhateverPlugin extends Plugin
{
}
}
Run Code Online (Sandbox Code Playgroud)
我想有一个自定义构造函数,在插件的构造函数之前执行一些代码.
听起来你可能想要:
using System;
namespace CServer.API
{
public class Plugin
{
protected Plugin()
{
// This code will execute before the body of the constructor
// in WhateverPlugin
}
}
}
Run Code Online (Sandbox Code Playgroud)
和
using System;
using CServer.API;
namespace Whatever
{
// : is broadly equivalent to both implements and extends
public class WhateverPlugin : Plugin
{
public WhateverPlugin() // implicitly calls base constructor
{
// This will execute after the Plugin constructor body
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意,restricted它不是Java中的关键字; 我假设你的意思是protected.