c# - 功能(): this(null) {}

标签 c# syntax constructor null class-constructors

谁能解释一下下面的语法糖?

protected MyConstructor() : this(null)

主要是我对这部分感兴趣:“: this(null)

我知道 protected、constructors 和“this”关键字是如何工作的,但我很困惑,在我所有的在线搜索中都找不到最后一部分的任何详细信息。

编辑:我应该补充一点,它在公共(public)抽象类中。所以我猜构造函数正在调用实现者构造函数。

谢谢

最佳答案

它调用另一个具有参数的类构造函数:

protected MyConstructor() : this(null) { }  // This calls the other constructor

protected MyConstructor(object whatever)
{
    Frob(whatever);
}

关于c# - 功能(): this(null) {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21144231/

相关文章:

c# - UWP AppX 安装参数

c# - WIF 身份验证方案。 STS实现问题

syntax - Scheme核心语言规范

基类构造函数中的 C++ 引用

java - JAX-WS(TomEE) Web 服务构造函数仅运行一次

c++ - C++中构造函数的初始化顺序

c# - Log4net 未登录 Azure Web 应用程序

c# - 我可以将 C# 扩展方法的可见性限制为同一程序集中的类吗?

python - 尝试在 python 中定义多个函数时出现语法错误?

java - 在扩展类中强制使用某个函数,可能吗?