c#中的继承

Nir*_*bey 4 c#

有什么区别

class abc : qwe
{  
}  
Run Code Online (Sandbox Code Playgroud)

class zxc : qwe
{  
    zxc() : base(new someAnotherclass()).  
    {
    }    
}
Run Code Online (Sandbox Code Playgroud)

Giu*_*uto 10

区别在于,在您的第一个代码片段中,您正在调用无参数基类构造函数,而在您的第二个代码段中,您将使用参数调用基类构造函数.

您的基类可能定义如下:

class qwe{
    public qwe(){ /* Some code */ }

    public qwe(SomeAnotherclass ac){ /* Some other code */ }
}
Run Code Online (Sandbox Code Playgroud)

您的abc类的默认构造函数与以下内容完全相同:

class abc{
    public abc() : base() {}    
}
Run Code Online (Sandbox Code Playgroud)