I cannot grasp the usage of those constructors.
I understand that one is as follows:
public book(){
private string author;
private string title;
private int reference;
}
And a parametrised constructor is as follows:
public book( string author, string title, int reference){
}
However how would this be used in a main method?
There are three ways you can have a constructor:
1) You declare a no-parameter one
.
2) You declare one with parameters
.
3) You let the compiler declare one for you — this requires you do not declare one of your own. In this case the member variables will be provided a default value based on their type (essentially their no-parameter constructor called)
You can mix options 1) and 2), but 3) is stand-alone (cannot mix it with any of the other two). You can also have more than one constructors with parameters (the parameter types/numbers must be different)
An example use: