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 moreIs 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 moreShould I use constructors in C#?
The main use of constructors is to initialize the private fields of the class while creating an instance for the class . When you have not created a constructor in the class, the compiler will automatically create a default constructor of the class.
Read more