How to implement the C # constructor
This article introduces the relevant knowledge of "how to implement the C# constructor". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Select C # constructor
The base class object is always constructed before any derived class. Therefore, the constructor of the base class is executed before the constructor of the derived class. If the base class has more than one constructor, the derived class can decide which constructor to call. For example, we can modify our Point class to add a second constructor:
Public class Point {private int x, y; public Point () {x = 0; y = 0;} public Point (int x, int y) {this.x = x; this.y = y;}}
Then, by using the base keyword, we can change the ColorPoint class to use a specific selection C # constructor:
Public class ColorPoint: Point {private Color color; public ColorPoint (int x, int y): base (x, y) {color = Color.Red;}}
In Java, this function is achieved through the super keyword.
This is the end of the content of "how to implement the C # constructor". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!