{"id":4772,"date":"2014-03-30T15:18:17","date_gmt":"2014-03-30T15:18:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-is-long-being-allowed-as-array-length-in-c-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:18:17","modified_gmt":"2014-03-30T15:18:17","slug":"why-is-long-being-allowed-as-array-length-in-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/why-is-long-being-allowed-as-array-length-in-c-collection-of-common-programming-errors\/","title":{"rendered":"Why is &ldquo;long&rdquo; being allowed as array length in C#?-Collection of common programming errors"},"content":{"rendered":"<p>It is a limitation of the CLR, no single object can exceed 2GB, including arrays:<\/p>\n<p>Large array C# OutOfMemoryException<\/p>\n<p>This is regardless of 32-bit or 64-bit OSs. That said, it doesn&#8217;t stop you from using more than that amount in total, just not on one object.<\/p>\n<p>It is a <strong><em>runtime<\/em><\/strong> error because if you keep the <code>long<\/code> (or other initializing value) within range, it will work.<\/p>\n<p>You can initialize arrays with all integral types: <code>sbyte<\/code>, <code>char<\/code>, <code>short<\/code>, <code>int<\/code>, and <code>long<\/code> &#8211; all compile; the unsigned variants work too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is a limitation of the CLR, no single object can exceed 2GB, including arrays: Large array C# OutOfMemoryException This is regardless of 32-bit or 64-bit OSs. That said, it doesn&#8217;t stop you from using more than that amount in total, just not on one object. It is a runtime error because if you keep [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4772","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4772"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4772\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}