Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inheritance in c#

Tags:

c#

what is the difference between

class abc : qwe
{  
}  

and

class zxc : qwe
{  
    zxc() : base(new someAnotherclass()).  
    {
    }    
}
like image 712
Niraj Choubey Avatar asked Dec 28 '22 08:12

Niraj Choubey


1 Answers

The difference is, that in your first code snippet you're calling the parameterless base class constructor, whereas in your second code snippet you're calling the base class constructor with a parameter.

Your base class might be defined as follows:

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

    public qwe(SomeAnotherclass ac){ /* Some other code */ }
}

The default constructor for your abc class looks exactly like the following:

class abc{
    public abc() : base() {}    
}
like image 115
Giuseppe Accaputo Avatar answered Jan 11 '23 14:01

Giuseppe Accaputo