Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all first of all I am sorry because my first language is not English.

I want to know maximum range of any reference types in c#

For example I know the byte data types maximum range is 0 to 255 but I don't know exactly maximum range of reference types like string,object etc


If I understood correctly any reference types range is 2GigByte (if this is true just say true without any Something extra) on 32bit and 64bit platform

thanks a lot

What I have tried:

I try to ask question in MSDN but I did not get about exactly range of reference types
Posted
Updated 7-Feb-20 22:42pm
v3

You don't seem to understand what a reference type is: it doesn't have a "max range" in the sense you seem to think.

A reference type is restricted by the Heap, not by the type: a string does have a "range", it's an immutable value with a theoretical maximum length of 2,147,483,647 characters in theory (because it's Length property is an int value, and that's the largest value it can hold. Similarly, the Length property of an array is also an int - but .NET had a maximum allocation size of 2GB prior to .NET 4.5 so no single object (and an array is a single object) can exceed that. Post 4.5, it is possible to get 4GB objects in 64 bit systems, but even that won't allow you an array containing 4G worth of values in most cases, because very few value types are less than 8 bytes, and an array of references is always going to be 8 bytes * the number of elements in the array.

The "range" of an object is undefined because everything is an object even if it's a value type - so object has no fixed size at all.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900