modifier : Hides the members in the base class (is a member of the base class, so fields, properties, events, and so on can be hidden, not just methods)
public class car{public void Writename (string name) { Console.WriteLine (name);} } public class newcar:car{public void Writename (string name) { Console.WriteLine ("Car Name": +name);} }
There is an error in this code: vs will Prompt
In order to enable subclasses to use Writename This method, we have to use the New keyword to hide the method in the parent class, or we have created a new Writename method, which is generally used when writing third-party plugins
public class newcar:car{ //Use New to hide methods in the base class public new void Writename (string name) { Console.WriteLine (" Car name ": +name);} }
Of course, if you want to use a member of the parent class, just show the transformation.
constraint : The new constraint specifies that any type parameter in a generic class declaration must have a public parameterless constructor. It is important to note that if you want to use the new constraint, the type cannot be an abstract type;
When there are multiple constraints in a generic class, the new constraint must be written in the last
public class cars<t> where t:icomparable, new () {}
The basic usage of new is so much, and of course there are some other small points of knowledge, such as creating anonymous classes and so on.
About the use of new in C #