Am I calling the base constructor when getting from ServiceBase?

The Microsoft.NET documentation for the System.ServiceProcess.ServiceBase class constructor states:

If you override the constructor of the base class, you must explicitly call this in the constructor of your derived class.

In Using Constructors in the Microsoft C # Programming Guide, it says:

In a derived class, if the base class constructor is not explicitly called using the base keyword, the default constructor, if there is one, is called implicit.

So do I need to explicitly call the base constructor or not, and why?

+6
source share
1 answer

It does not matter. They compile with the same IL:

public class Service1 : ServiceBase { public Service1() : base() { } } public class Service1 : ServiceBase { public Service1() { } } 

I do not know why ServiceBase recommends explicitly calling it. I would go with another suggestion, as that makes sense.

+5
source

Source: https://habr.com/ru/post/919525/


All Articles