CSharp-Pills-15mg / Virtual-in-Constructor

This pill demonstrates why it is not a good idea to call abstract or virtual methods from the constructor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Virtual in Constructor

Pill Category

Language (C#)

Description

If we call a virtual method from the constructor, Resharper raises a warning: "Virtual member call in constructor"

Same warning is raised if we call an abstract method and also if we call a virtual or abstract property.

Question

  • Why is it a problem to call virtual or abstract methods or properties from the constructor?

Donations

If you like my work and want to support me, you can buy me a coffee:

ko-fi

About

This pill demonstrates why it is not a good idea to call abstract or virtual methods from the constructor.

License:GNU General Public License v3.0


Languages

Language:C# 100.0%