C # class and object learning,
A class is a reference type and a custom type.
Style:
* Class name * {* field member * function member *}
When no explicitly declared instance constructor exists in the class, the system will provide it with a public no-argument instance constructor by default.
If another instance constructor exists, the system will not provide it by default. If you want to operate the non-argument instance constructor, You need to explicitly declare it yourself.
The instance fields in the class do not require a value assignment in the constructor.
The instance constructor is used to create and initialize an object.
Class Person {// The instance field in the class can be initialized string name = "lily"; // The system will initialize uninitialized instance fields in the class by default, the initial value is the type default value int age; // No parameter public instance constructor public Person () {}// public Person (string name, int age) {this. name = name; this. age = age;} public void ShowInfo () {Console. writeLine ("name: {0} age: {1}", name, age) ;}} class Program {static void Main (string [] args) {// declare that the referenced variable Person person = null; // when the referenced variable is null, the instance Member cannot be accessed, causing a crash. // person. showInfo (); // create object person = new Person (); person. showInfo (); // change the point of person to point to a new object person = new Person ("Coco", 17); person. showInfo (); // use the referenced variable to assign a value to another referenced variable. The two referenced variables point to the same object Person person00 = person; Console. readKey ();}}