Can I build a long list <int> so that the index is long?

Currently, a List<int> index can accept Int32, can I upgrade to Int64?

Therefore, I can use something like mylist [1000000000000].

+6
source share
3 answers

No, you can’t.

This would not be useful if it were allowed. The CLR has a maximum object size limit of 2 GB. Therefore, it is not even possible to build an array in which the long index is useful.

+13
source

You cannot change the Framework <> interface, which indicates the type of the index argument as int . But you can create your own type that takes a long index.

As JaredPar noted, you cannot create an array that is large enough to require a 64-bit index. If you want to create a list in which you can store so many elements, you will have to use some kind of tree structure or arrays of arrays or something like that. And you will need a lot of memory!

0
source

You may have a list that will contain long values ​​or numbers in excess of 2,147,483,647.

 List<long> list = new List<long>(); list.Add(3000000000) will work. 
-4
source

Source: https://habr.com/ru/post/900223/


All Articles