C# – Example of Class with Two Constructors – Video

Sometimes you should create more than one constructor for a class. This is a useful practice, if you need to generate objects of the same type which need to be initiated with different fields. In the current example, we generate four objects – “Football Teams” and we define these football teams with a “Name”, “FamousPlayer”, “City” and “Country”. Furthermore, we develop a simple void method, which gives us information for those football teams.
The teams are put in an array and with a foreach loop the method given information is called. At the end of the program we have the following:
Picture


which is pretty much what we wanted to achieve.

 

One last interesting note – for the execution of the method the objects are put into an array. Then with the help of a foreach loop, the method is called for each one of them.

Here comes the code: