Classes

As previously stated, IL is not an OO language in itself. For IL to support multiple source languages and constructs, IL supports the notion of creating classes and creating instances of classes. Looking at the IL for declaring and creating classes will give you a better understanding of the Common Language Specification (CLS). Listing 1.3.3 shows the IL code for creating and using a class.

Listing 1.3.3. Creating a Class in IL
 1: .assembly class_test as "class_test" 2: { 3: .ver 1:0:0:0 4: } 5: 6: 7: .module class_test.exe 8: 9: 10: //Create a class Dog with two public fields 11: 12: .class public auto ansi Dog extends [mscorlib]System.Object { 13: 14: //public data fields 15: .field public class System.String m_Name 16: .field public ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.