![](/img/trans.png)
[英]In C# what category does the colon “ : ” fall into, and what does it really mean?
[英]What does this colon mean in this C# code?
在C#中的類或接口定義中指示了什么:
public interface IServer : IServerManager, ISimulation, ISiteEx
{
/// <summary>
/// Returns the highest game version that supported by this server.
/// Higher versions aren't guaranteed to work perfect.
/// </summary>
Version MaxSupportedGameVersion { get; }
/// <summary>
/// Gets/sets the current server configuration.
/// </summary>
ServerConfiguration Configuration { get; set; }
}
:
用於指示運算符左側的接口正在實現(技術上,實現接口的類將給出實現)右側的接口。
:
以相同的方式用於指示類何時實現一個或多個接口。
因為IServer
是一個接口,冒號意味着IServer
接口繼承了IServerManager
, ISimulation
, ISiteEx
接口。 換句話說:任何實現IServer
類或結構也必須實現其他三個。
如果冒號左側的類型是類或結構,冒號將指示類或結構實現接口。 同樣在這種情況下,如果右側的一個(並且只有一個)類型是一個類,則意味着左側的類型繼承自該類。 類可以從許多接口繼承,但只能從一個類繼承。
這意味着接口正在實現另一個接口或多個接口。
:是在c#中實現繼承的方法有多種方案可以使用它。
擴展另一個接口的接口(問題中的示例就是這種情況。)
實現接口的類
擴展另一個類的類
一個類可以實現多個接口,但它只能擴展一個類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.