开发者

Does Enumerable.Repeat() do a deep copy?

开发者 https://www.devze.com 2022-12-16 07:13 出处:网络
If I use the following: var myList = Enumerable.Repeat(myCustomObject, 2); 开发者_C百科 Will the Second element in the list be a deep copy of the first one?

If I use the following:

  var myList = Enumerable.Repeat(myCustomObject, 2);
开发者_C百科

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


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

-Oisin


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消