Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Array.Copy support Long Arguments

Tags:

arrays

c#

From the MSDN:

Parameters sourceArray

The Array that contains the data to copy. destinationArray

The Array that receives the data. length

A 64-bit integer that represents the number of elements to copy. The integer must be between zero and Int32.MaxValue, inclusive

Given that the permitted range of values is 0 to Int32.MaxValue, what is the motivation for adding this signature? It did not exist in .Net 1.0 and was only added in .Net 1.1. My only guess is to prepare for 64-bit Framework implementations.

like image 651
Brian Avatar asked Sep 21 '10 21:09

Brian


1 Answers

Curiously an array also has overloads for GetItem that take either an Int32 and an Int64. But in practice you cannot have a single object larger than 2 gigabytes in the current implementation of the .NET framework so you can't actually create an array that allows such large indexes.

I guess if this restriction were lifted later then it would mean that they don't need to change the interface.

like image 162
Mark Byers Avatar answered Oct 21 '22 13:10

Mark Byers