[英]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.