
Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
Hello Nicholas,
I'm still not sure if I understand this correctly.
Does a List<T> object holds a bunch of objects of type T or
Does it only hold the references (addresses?) of those objects?
I certainly don't want each task to hold copies of all its prerequisites and
dependent tasks.
Thanks,
Bob
> Robert,
>
[quoted text clipped - 34 lines]
>>>
>>> Marc
Jon Skeet [C# MVP] - 14 Feb 2008 00:21 GMT
> I'm still not sure if I understand this correctly.
> Does a List<T> object holds a bunch of objects of type T or
> Does it only hold the references (addresses?) of those objects?
>
> I certainly don't want each task to hold copies of all its prerequisites and
> dependent tasks.
Assuming T is a reference type (e.g. a class) then it only holds
references.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Robert Wells - 14 Feb 2008 00:29 GMT
Thank You!
>> I'm still not sure if I understand this correctly.
>> Does a List<T> object holds a bunch of objects of type T or
[quoted text clipped - 6 lines]
> Assuming T is a reference type (e.g. a class) then it only holds
> references.
Marc Gravell - 14 Feb 2008 05:10 GMT
As Jon has stated - references; that is why I added my "where T is a
class (not a struct)" caveat to my original reply.
In .NET, and very unlike C++, there is a large and fundamental
difference between "struct" and "class". A struct (examples: int,
float, DateTime, etc) follows value-type semantics, and will copy
itself (memcopy) sooner than you can glance at it - i.e.
int x = 5;
int y = x; // [memcopy of the struct]
Because of this, structs are almots always immutable (non-editable
once created), because it just gets too confusing to think about them
otherwise.
In contrast, classes have reference-type semantics. "new" creates a
new object on the managed heap, and the field/variable just holds the
referenece (think: pointer). Most .NET types are classes. Assignment
of variables copies *the reference*, not the object:
Foo x = new Foo();
Foo y = x; // reference value is copied, both x & y point to same Foo
Marc
Robert Wells - 15 Feb 2008 17:11 GMT
Thank you!
> As Jon has stated - references; that is why I added my "where T is a
> class (not a struct)" caveat to my original reply.
[quoted text clipped - 20 lines]
>
> Marc