Hello LCG

The LCG Hello World example is shown here, simply printing “Hello LCG!” to the screen based on a dynamically generated assembly:

// An assembly...var asm = AppDomain.CurrentDomain.DefineDynamicAssembly(    new AssemblyName("LCGDemo"),    AssemblyBuilderAccess.Run);// ...contains a module...var mod = asm.DefineDynamicModule("MyModule");// ...contains a type...var tpe = mod.DefineType("Sample");// ...contains a method...var mtd = tpe.DefineMethod("SayHello",                           MethodAttributes.Public | MethodAttributes.Static);// ...contains a code body...var gen = mtd.GetILGenerator();gen.Emit(OpCodes.Ldstr, "Hello LCG!");                    // The mythical infoof(Console.WriteLine(string))gen.Emit(OpCodes.Call, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.