[英]Equivalent to Java's “restricted” and “extends” in C#?
编辑:我很抱歉,我的意思是protected
而不是restricted
。 我好累
是否有等效于Java的restricted
并在C#中extends
? 我可以看到它们都不在C#中,它们对于当前的编程项目很有用。
码:
using System;
namespace CServer.API
{
public class Plugin
{
restricted Plugin ()
{
}
}
}
并说一个插件做到了:
using System;
using CServer.API;
namespace Whatever
{
public class WhateverPlugin extends Plugin
{
}
}
我想要一个自定义的构造函数,该函数在插件的构造函数之前执行一些代码。
听起来您可能想要:
using System;
namespace CServer.API
{
public class Plugin
{
protected Plugin()
{
// This code will execute before the body of the constructor
// in WhateverPlugin
}
}
}
和
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
}
}
}
请注意, restricted
并不是Java中的关键字。 我假设您实际上是在说protected
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.