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

前端 未结 2 1256
执笔经年
执笔经年 2020-12-16 08:53

I deal with a framework on a daily basis where we sometimes provide methods that accept IEnumerable as a parameter in order to show user

2条回答
  •  不知归路
    2020-12-16 09:52

    You will get a new copy of the array if there is one or more element in it. For empty arrays, you might get the same array back, at least in .NET 5:

    Console.WriteLine(Object.ReferenceEquals(Array.Empty(), Array.Empty().ToArray()));
    

    This returns true.

提交回复
热议问题