帮我理解c#中的这段代码

Tar*_*ied 0 c# constructor

我无法阅读这行代码

public Wine (decimal price, int year) : this (price) { Year = year; }
Run Code Online (Sandbox Code Playgroud)

什么:this在构造函数中的关键字做

public class Wine
{
    public decimal Price;
    public int Year;

    public Wine (decimal price) 
    { 
        Price = price; 
    }

    public Wine (decimal price, int year) : this (price) 
    { 
        Year = year; 
    }
}
Run Code Online (Sandbox Code Playgroud)

kla*_*her 5

这称为构造函数链接.您只需调用它,而不是重写单参数构造函数的代码.C#通过使用带冒号的简短表示法使这简单.