views:

115

answers:

2

Hi all,

If I use the following:

  var myList = Enumerable.Repeat(myCustomObject, 2);

Will the Second element in the list be a deep copy of the first one?

Note: myCustomObject can be any Object

Edit: Could you also please let me know the potential use of Enumerable.Repeat when dealing with custom objets?

Thanks

+4  A: 

No, Enumerable.Repeat will just repeat the reference, it won't make a copy of the object (unless it's a value type of course)

Thomas Levesque
+5  A: 

No, Enumerable.Repeat actually repeats the exact same reference in the enumerable returned - it is not a copy. (verified via Reflector)

-Oisin

x0n
unless the object is of value type...
Thomas Levesque