Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I construct a long list<int> such that the index is long?

Tags:

c#

currently the index a List<int> can take is Int32, can I go for Int64?

So i can use something like mylist[1000000000000].

like image 863
colinfang Avatar asked Oct 27 '11 17:10

colinfang


People also ask

Can ArrayList index be long?

You can't make an ArrayList (or for that matter an int[] array) that has a long for its index.

Can we use long in array index in Java?

An attempt to access an array component with a long index value results in a compile-time error. If for some reason you have an index stored in a long, just cast it to an int and then index your array. You cannot create an array large enough so it cannot be indexed by an integer in Java.

Can arrays index?

It is not possible to define an array section using Indexes, but one can use them in gather/scatter-like operations. The only restriction is that elements in an Index must be nonnegative. The same value can appear multiple times in an Index.


1 Answers

No you cannot.

This would not be useful if it was allowed. The CLR has a limit on the maximum size of an object at 2GB. Hence it's not even possible to construct an array where a long index would be useful.

like image 107
JaredPar Avatar answered Oct 22 '22 16:10

JaredPar