这个冒号在这个C#代码中意味着什么?

use*_*640 7 c# inheritance

在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; }
}
Run Code Online (Sandbox Code Playgroud)

man*_*lds 7

: 用于指示运算符左侧的接口正在实现(技术上,实现接口的类将给出实现)右侧的接口.

: 以相同的方式使用以指示类何时实现一个或多个接口.


Jef*_*Sax 5

因为IServer是一个接口,结肠意味着该IServer接口从继承IServerManager,ISimulation,ISiteEx接口.换句话说:任何实现的类或结构也IServer必须实现其他三个.

如果冒号左侧的类型是类或结构,冒号将指示类或结构实现接口.同样在这种情况下,如果右侧的一个(并且只有一个)类型是一个类,则意味着左侧的类型继承自该类.类可以从许多接口继承,但只能从一个类继承.


Mah*_*eep 5

:是c#中实现继承的方式,有多种场景可以使用它。

  1. 扩展另一个接口的接口。(您问题中的示例就是这种情况。)

  2. 实现接口的类

  3. 一个类扩展另一个类

一个类可以实现多个接口,但只能扩展一个类。