struct type: value type, and class is reference type
Structure definition:
-
Structs are defined in much the same way as classes, but structs are value types, and classes are reference types;
-
object is a reference type, when assigning an object to a variable, it assigns a pointer to the object that the pointer points to, changes one of the values, and the value changes;
Using system;using system.collections.generic;using system.linq;using system.text;using system.threading.tasks;namespace consoleapplication1{ class program { class MyClass { public int val; } struct MyStruct { public int val; } static void main (String [] args) { myclass objeCta = new myclass (); myclass objectb = objecta; objectA.val = 100; Objectb.val = 200; mystruct structa = new mystruct (); MyStruct StructB = StructA; StructA.val = 100; StructB.val = 200; console.writeline ("object a = {0}", Objecta.val); consoLe. WriteLine ("object b = {0}", Objectb.val); console.writeline ("struct a = {0}", Structa.val); console.writeline ("struct b = {0}", Structb.val); console.readline (); } }}
Results:
Object A =200
Object B =200
Struct A =100
Struct B =200
This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1651625
. C #-struct type, reference type