Girish Jain <[EMAIL PROTECTED]> wrote:

> **For the following C# code**
> 
> int k = new int();

This is identical to:

  k = 0;

> k = 100;
> Console.WriteLine(k.ToString());
>   .locals init (int32 V_0)
>   IL_0000:  ldc.i4.0
>   IL_0001:  stloc.0

Here you can see "k = 0"

>   IL_0002:  ldc.i4.s   100
>   IL_0004:  stloc.0

And here "k = 100"

> and looking at the above it is clear that it creates two ints (the reason of
> which is still not clear to me as to why it is creating two ints?).

It doesn't create two ints. It initializes the variable with a value,
zero.

> Also, why would anyone need to use new operator with value types (unless
> looping over a collection and adding items to it by using the same variable
> but creating a new object each time)

How else do you initialize a structure to all-zeros? There is no memset
function in C# :)

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to