-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: laks_win
Message 6 in Discussion
Wow..its really a sensible
explanation!!!
Keep it up.
Regards
Laks.R
----- Original Message -----
From:
Anand_2004
To: BDOTNET
Sent: Tuesday, March 15, 2005 2:48
PM
Subject: Re: unboxing?
New Message on BDOTNET
unboxing?
Reply
Reply to Sender Recommend
Message 5 in
Discussion
From: Anand_2004
Hi,
To explore this its ideal to look at the IL code of the
program .Its look like as below
method private hidebysig static void Main(string[]
args) cil managed
{
.entrypoint
custom
instance void [mscorlib]System.STAThreadAttribute::.ctor() = (
01 00 00 00 )
// Code
size 37 (0x25)
.maxstack 1
.locals init ([0] string
initial,
[1] object
o,
[2] string
'final',
[3] string
IsUnboxing,
[4] string IsUnboxing1)
IL_0000:
ldstr "Initialize"
IL_0005: stloc.0
IL_0006:
ldloc.0
IL_0007: stloc.1
IL_0008: ldstr
"Re-Initialize"
IL_000d: stloc.0
IL_000e: ldloc.1
IL_000f: castclass
[mscorlib]System.String
IL_0014:
stloc.2
IL_0015: ldloc.1
IL_0016: callvirt instance string
[mscorlib]System.Object::ToString()
IL_001b:
stloc.3
IL_001c: ldloc.1
IL_001d: isinst
[mscorlib]System.String
IL_0022:
stloc.s IsUnboxing1
IL_0024:
ret
} // end of method Class1::Main
its clearly says there is no boxing or unboxing , actually
its called up-casting and down-casting operation .if we look at
another example
static void Main1()
{
int
i=500;
object
obj=i;
obj=400;
i = (int) obj;
}
the IL code of the above code is
.method private hidebysig static void Main1() cil
managed
{
// Code
size 33 (0x21)
.maxstack 1
.locals init ([0] int32
i,
[1] object obj)
IL_0000:
ldc.i4 0x1f4
IL_0005:
stloc.0
IL_0006: ldloc.0
IL_0007: box
[mscorlib]System.Int32
IL_000c:
stloc.1
IL_000d: ldc.i4
0x190
IL_0012:
box
[mscorlib]System.Int32
IL_0017:
stloc.1
IL_0018: ldloc.1
IL_0019: unbox
[mscorlib]System.Int32
IL_001e:
ldind.i4
IL_001f: stloc.0
IL_0020: ret
} // end of method Class1::Main1
have a look at the unbox and box
symbols that means in this scenario its actually
doing boxing and unboxing.
HTH
Cheers
Thanx<o:p></o:p>
Anand<o:p></o:p>
Blog @
http://spaces.msn.com/members/anandkumar
View other groups in this
category.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]