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 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.