Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can one class inherit from an other class an have implemented an interface at same time?

Tags:

c#

inheritance

somthing like

public partial class RegistrationForm : 
          IRegistrationForm, System.Web.UI.UserControl

but this example does not work.

like image 560
user137348 Avatar asked Dec 05 '22 04:12

user137348


2 Answers

Yes, but you do it like this:

public partial class RegistrationForm : System.Web.UI.UserControl, IRegistrationForm

C# doesn't support multiple inheritance, so you put the class you inherit from first, followed by a comma, followed by a comma-delimited list of the interfaces it implements.

like image 162
Neil Barnwell Avatar answered Jan 01 '23 12:01

Neil Barnwell


Absolutely, a class can inherit from a single base class and implement any number of interfaces at the same time.

Your example does not work because the one base class must be listed first, before all the interfaces...

like image 20
Charles Bretana Avatar answered Jan 01 '23 12:01

Charles Bretana