JAL Computing

C++COMProgramming .NET Mac Palm CPP/CLI Hobbies

 

Home
Up

Instance Method and Field

CIL code from a simple class with a single string field and DoIt method.

C# Source Code

using System;
namespace TestILInstance
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		private string message= "Hello World!";
		public void DoIt() 
		{
			System.Console.WriteLine(message);
		}
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: Add code to start application here
			//
			Class1 c1= new Class1();
			c1.DoIt();
		}
	}
}

Common Intermediate Language Code

.class private auto ansi beforefieldinit

.class private auto ansi beforefieldinit Class1
extends [mscorlib]System.Object
{
} // end of class Class1

message:private string

.field private string message

.ctor : void()

.method public hidebysig specialname rtspecialname 
instance void .ctor() cil managed
{
// Code size 18 (0x12)
.maxstack 2
IL_0000: ldarg.0
IL_0001: ldstr "Hello World!"
IL_0006: stfld string TestILInstance.Class1::message
IL_000b: ldarg.0
IL_000c: call instance void [mscorlib]System.Object::.ctor()
IL_0011: ret
} // end of method Class1::.ctor

DoIt : void()

.method public hidebysig instance void DoIt() cil managed
{
// Code size 12 (0xc)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld string TestILInstance.Class1::message
IL_0006: call void [mscorlib]System.Console::WriteLine(string)
IL_000b: ret
} // end of method Class1::DoIt

Main : void(string[])

.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) 
// Code size 13 (0xd)
.maxstack 1
.locals init ([0] class TestILInstance.Class1 c1)
IL_0000: newobj instance void TestILInstance.Class1::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: callvirt instance void TestILInstance.Class1::DoIt()
IL_000c: ret
} // end of method Class1::Main

Send mail to [email protected] with questions or comments about this web site. Copyright © 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 © 
Last modified: 08/04/09
Hosted by www.Geocities.ws

1