Re: int number = new int();
- From: "Tony Johansson" <t.johansson@xxxxxxxxxx>
- Date: Fri, 26 Sep 2008 16:15:16 +0200
Hello!
I just wonder if it's then correct to say that
Int32 is a structure they never are placed on the heap.I mean when you are boxing a copy is actually stored on the heap
as I described
//Tony
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message news:73b37d53-7e92-4e35-b5d8-f5d96ce40be2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 26, 2:28 pm, "Tony Johansson" <t.johans...@xxxxxxxxxx> wrote:
Assume you have the following.
int number = 1;
object o = number;
If you here change the value of number it won't change what o is refering to
because that is stored on the heap.
Yes.
So we have one value of number which is stored on the stack and when we do
object o = number
a copy of this actual value number is put on the heap.
Yes.
If we now change number by using this statement
number = 2;
the number that o is refering to is still 1;
Correct.
I almost 99.99 % sure that this is correct.
Absolutely. I was merely correcting this statement that you made
before:
// so o is stored on the stack and will
// reference number which is stored on the heap.
"o" doesn't reference "number". It reference an object which was
created with a value which happened to be the value of "number" at the
time. The two variables are independent immediately after the
assignment.
Jon
.
- Follow-Ups:
- Re: int number = new int();
- From: Jon Skeet [C# MVP]
- Re: int number = new int();
- References:
- int number = new int();
- From: Tony Johansson
- Re: int number = new int();
- From: Cor Ligthert [MVP]
- Re: int number = new int();
- From: Tony Johansson
- Re: int number = new int();
- From: Jon Skeet [C# MVP]
- Re: int number = new int();
- From: Tony Johansson
- Re: int number = new int();
- From: Jon Skeet [C# MVP]
- int number = new int();
- Prev by Date: Re: count days including weekend
- Next by Date: ICompare class for a list of struct with generic fields
- Previous by thread: Re: int number = new int();
- Next by thread: Re: int number = new int();
- Index(es):
Relevant Pages
|