Using system;using system.collections.generic;using system.linq;using system.text;namespace c_ Edit Base { class person {public string Name;//Because name is not assigned, and it is of type string, its default value is null public int age; Because age and gender are not assigned. And it's two int types, so the default value for both of them is 0 public int Gender; public void SayHello () { Console.WriteLine ("Good Everyone"); Console.readkey (); } } Class program { static void Main (string[] args) { //int i = 1;//value type initialization is a direct assignment. The initialization of a reference type requires the new person, p1 = new Person (), or//new person () to create a person class object.person P1 = new person () means creating an object of the person type first and then using the variable P1 to point to it P1.sayhello ();}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
C # Create and Initialize classes