Global Methods

Global Methods

Global methods, similar to global fields, are defined outside any class scope. Most of the features of global fields and global methods are also similar: global methods are all static, and the accessibility flags for both mean the same.

Of course, one global method worth a special mention is the global class constructor, .cctor. As the preceding chapter discussed, a global .cctor is the best way to initialize global fields. The following code snippet from the sample file Gcctor.il on the companion CD provides an example:

.field private static string Hello .method private static void .cctor( ) {    ldstr "Hi there! What's up?"    stsfld string Hello    ret} .method public static void Exec( ) {    .entrypoint    ldsfld string Hello // Global fields are accessible                        // within the module    call void [mscorlib]System.Console::WriteLine(string)    ret }



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net