Is constructor a good practice?

Constructors are meant to initialize the data fields in the object. Given the choices, the second approach seems more correct. Although what might be better is to include the doDFS method in your graph object. It’s usually bad practice to create an entire class for a single simple function .

Read more

What is this () in constructor in C#?

The “this” keyword in C# is used to refer to the current instance of the class . It is also used to differentiate between the method parameters and class fields if they both have the same name. Another usage of “this” keyword is to call another constructor from a constructor in the same class.

Read more

How do constructors work in C#?

In c#, Constructor is a method that will invoke automatically whenever an instance of class or struct is created . The constructor will have the same name as the class or struct, and it is useful to initialize and set default values for the data members of the new object.

Read more