Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:22:24+00:00 2026-06-05T22:22:24+00:00

Consider the following: long size = int.MaxValue; long[] huge = new long[size]; // throws

  • 0

Consider the following:

long size = int.MaxValue;
long[] huge = new long[size];     // throws OutOfMemoryException
long[] huge = new long[size + 1]; // throws OverflowException

I know there is a 2GB limit on the size of a single object, which explains the first exception, but why do I get a different exception once the number of elements surpasses 32bits?

(I am using a 64-bit computer if that’s important).

EDIT: I can also define and use an indexer that accepts a long with no problems:

internal sealed class MyClass
{
   public object this[long x]
   { 
      get
      {
         Console.WriteLine("{0}", x);
         return null;
      }
   }
}

...

long size = int.MaxValue;
MyClass asdf = new MyClass();
object o = asdf[size * 50]; // outputs 107374182350
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:22:25+00:00Added an answer on June 5, 2026 at 10:22 pm

    So from what I’ve gathered, something like the following is happening here:

    • Indexers in general could use any type of parameter.
    • The built-in array indexers can accept any integral type…
    • But the underlying implementation of the built-in array indexers requires a value that is <= Int32.MaxValue and will throw an overflow exception for a value that exceeds Int32.MaxValue.

    While the latter point feels like some kind of weird contradiction (accepting types larger than Int32, but throwing an exception if you happen to actually use any of those extra bits), it is apparently a side-effect of the fact that some of this is half-implemented for the future implementation of arrays which will be allowed to have more than Int32.MaxValue elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: char* p = new char[2]; long* pi = (long*) p;
Consider the following piece of code. int var; cout << (long)&var; My doubt is
Let's consider the following code: SimpleDateFormat sdf = new SimpleDateFormat(HH:mm:ss dd/MM/yyyy, Locale.US); long start
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following data in long format library(plyr) library(reshape2) x <- seq(0,2*pi,length=20) ll <-
Consider the following situation: public class Storage { public T GetSingleByID<T>(long id) where T
consider the following code addHash(hash); bool addHash(char* hash) { HKEY hKey = 0; int
Consider the following sample code: class SampleClass { public long SomeProperty { get; set;
Consider the following code: class Program { public static explicit operator long(Program x) {
Consider the following sample code: class MyClass { public long x; public void DoWork()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.