2 reference types
Includes class classes, interface interface, representing delegate, arrays array
Class 2.1
For value types, each variable directly contains all of its own data, creating a region in memory for each variable, and for reference types, each variable stores only a reference to the target data, and each variable creates a pointer to the target data.
Public Static voidMain () {//structureScontact S1 =Newscontact (); S1.m_name="Li Ming"; S1.m_age= -; S1.m_telephone="Unknown"; Scontact S2=S1; S2.m_name="Zhang San"; S2.m_age= -; S2.m_telephone="Unknown"; Console.WriteLine ("after modifying the structure variable:"); Console.WriteLine (S1.m_name); Console.WriteLine (S1.m_age); //classCcontact C1 =Newccontact (); C1.m_name="Li Ming"; C1.m_age= -; Ccontact C2=C1; C2.m_name="Zhang San"; C2.m_age= -; Console.WriteLine ("after modifying a class variable:"); Console.WriteLine (C1.m_name); Console.WriteLine (C1.m_age); } structScontact { Public stringM_name; Public intM_age; Public stringM_telephone; } classCcontact { Public stringM_name; Public intM_age; Public stringM_telephone ="Unknown"; }
View Code
Output Result:
After modifying the structure variable:
Li ming
20
After modifying a class variable:
Tom
25
Please press any key to continue ...
First C # data type (reference type)