Some people ask "Why can't I inherit the newguid method in System.Guid," The answer is very simple, because system.guid is the structure instead of the class. For example, define the following structure and class
Public struct mytype {public int myinteger;} public class class1: mytype {}
This code will throw compile error content as "class1: cannot inherit from timed class mytype". As follows:
Public struct mytype {public int myinteger;} public struct class1: mytype {}
The compilation error is as follows: "Class1: Type in interface list is not an interface".
The examples provided by Microsoft are listed in the example of the experience to learn // copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
// struct2.csusing system;
Class theclass {public int x;}
Struct theStruct {public int x;}
class TestClass {public static void structtaker (TheStruct s) {sx = 5;} public static void classtaker (TheClass c) {cx = 5;} public static void Main () {TheStruct a = new TheStruct (); TheClass b = new Theclass (); AX = 1; bx = 1; structtaker (a); classTaker (b); console.writeline ("ax = {0}", ax); console.writeline ("bx = {0}", BX );}} The output of this example is: AX = 1b.x = 5 From this example, it can be seen that when a structure is passed to a method, it is only a copy, and a class is passed. It is a reference. So AX = output is 1, the same is unchanged, and BX has changed. The difference is that the structure can be instantiated, but the class is. If you don't have new to instantiate A structure, then all fields will still be unallocated until all fields are initialized. Like the class, the structure can perform an interface. More importantly, the structure does not inheritability, a structure cannot inherit from other classes, Can't be a base class of other classes.