Does Array.ToArray<>() return the original array if it is the same type?

心已入冬 提交于 2019-11-29 02:48:51
Neil Barnwell

No, you will always get a new copy of the array, though the objects in it aren't copies, they are the same references as in the original array.

It would be very inconsistent for changes to the returned array to sometimes affect the source and sometimes not. ToList works the same way for the same reason.


You can check source code (as of 2015) if you need to review details: Enumerable.ToArray which in turn creates copy of elements (optimized for ICollection and hence Array[], but still making copy) with internal Buffer class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!