.assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class BranchExample { .method static public void Main() il managed { .entrypoint ldc.i4.5 ldc.i4.6 cgt brtrue greater ldstr "{0} is less than or equal to {1}" br end greater: ldstr "{0} is greater than {1}" end: ldc.i4.5 box int32 ldc.i4.6 box int32 call void [mscorlib] System.Console::WriteLine( string, object, object) ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class ForLoopExample { .method static public void Main() il managed { .entrypoint .locals (int32 count) ldc.i4.0 stloc.0 br.s loop for: ldloc count ldc.i4.1 add dup stloc count call void [mscorlib] System.Console::WriteLine(int32) loop: ldloc count ldc.i4.5 clt brtrue.s for ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class ObjectCreation { .method static public void Main() il managed { .entrypoint .locals (int32 temp) newobj instance void MyNamespace.SampleClass::.ctor() dup call instance int32 MyNamespace.SampleClass::AddFields() stloc.0 ldstr "The total is {0}" ldloc.0 box int32 call void [mscorlib] System.Console::WriteLine(string, object) call instance int32 MyNamespace.SampleClass::SubtractFields() stloc.0 ldstr "The difference is {0}" ldloc.0 box int32 call void [mscorlib] System.Console::WriteLine(string, object) ret } } .class SampleClass { .field static private int32 fielda .field private int32 fieldb .method private hidebysig specialname rtspecialname static void .cctor() cil managed { ldstr "In static constructor" call void [mscorlib] System.Console::WriteLine(string) ldc.i4.s 10 stsfld int32 MyNamespace.SampleClass::fielda ret } .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { ldstr "In constructor" call void [mscorlib] System.Console::WriteLine(string) ldarg.0 ldc.i4.s 5 stfld int32 MyNamespace.SampleClass::fieldb ret } .method public int32 AddFields() cil managed { ldsfld int32 MyNamespace.SampleClass::fielda ldarg.0 ldfld int32 MyNamespace.SampleClass::fieldb add ret } .method public int32 SubtractFields() cil managed { ldsfld int32 MyNamespace.SampleClass::fielda ldarg.0 ldfld int32 MyNamespace.SampleClass::fieldb sub ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class InheritanceExample { .method static public void Main() il managed { .entrypoint newobj instance void MyNamespace.DerivedClass::.ctor() dup call instance void MyNamespace.AbstractBaseClass::MethodA() callvirt instance void MyNamespace.DerivedClass::MethodC() ret } } .class abstract AbstractBaseClass { .method public instance void MethodA() il managed { ldstr "AbstractBaseClass::MethodA" call void [mscorlib] System.Console::WriteLine(string) ret } .method public virtual instance void MethodC() il managed { ldstr "AbstractBaseClass::MethodC" call void [mscorlib] System.Console::WriteLine(string) ret } } .class DerivedClass { .method public specialname rtspecialname instance void .ctor() cil managed { ret } .method public instance void MethodB() il managed { ldstr "DerivedClass::MethodB" call void [mscorlib] System.Console::WriteLine(string) ret } .method public virtual instance void MethodC() il managed { ldstr "DerivedClass::MethodC" call void [mscorlib] System.Console::WriteLine(string) ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class interface public abstract IA { .method public abstract virtual instance void MethodA() il managed { } } .class InterfaceExample { .method static public void Main() il managed { .entrypoint newobj instance void MyNamespace.Implementor::.ctor() callvirt void MyNamespace.Implementor::MethodA() ret } } .class Implementor implements MyNamespace.IA { .method public specialname rtspecialname instance void .ctor() cil managed { ret } .method public virtual instance void MethodA() il managed { ldstr "Implementor:MethodA" call void [mscorlib] System.Console::WriteLine(string) ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class StructureExample { .method static public void Main() il managed { .entrypoint .locals init (valuetype MyNamespace.MyStruct obj) ldloca.s obj ldc.i4.s 10 call instance void MyNamespace.MyStruct::.ctor(int32) ldloca.s obj ldfld int32 MyNamespace.MyStruct::fielda call void [mscorlib]System.Console::WriteLine(int32) ret } } .class value MyStruct { .field public int32 fielda .method public specialname rtspecialname instance void .ctor(int32) cil managed { ldarg.0 ldarg.1 stfld int32 MyNamespace.MyStruct::fielda ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class Starter { .method static public void Main() il managed { .entrypoint ldstr "Joe Bloggs" ldftn void MyNamespace.Starter::Name(string) calli void(string) ret } .method static public void Name(string) il managed { ldstr "Hello, {0}!" ldarg.0 call void [mscorlib] System.Console::WriteLine(string, object) ret } } } .assembly extern mscorlib {} .assembly application {} .namespace MyNamespace { .class JumpExample { .method static public void Main() il managed { .entrypoint ldstr "Hi There!" call void MyNamespace.JumpExample::ExecuteJump(string) ret } .method static public void ExecuteJump(string) il managed { ldstr "Before jump" call void [mscorlib] System.Console::WriteLine(string) ldstr "In ExecuteJump: {0}" ldarg.0 call void [mscorlib] System.Console::WriteLine(string, object) jmp void MyNamespace.JumpExample::ReceiveJump(string) ldstr "After jump" call void [mscorlib] System.Console::WriteLine(string) ret } .method static public void ReceiveJump(string) il managed { ldstr "In ReceiveJump: {0}" ldarg.0 call void [mscorlib] System.Console::WriteLine(string, object) ret } } }