![](/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.