Net-informations.com
SiteMap  | About    

Is string a value type or a reference type

In .Net Framework Strings are immutable reference types. All .net datatypes has default size except string and user type. So String is a Reference type, because its does not have default allocation size.

Is string a value type or a reference type C# vb.net asp.net

For ex: an integer (System.Int32 ) has fixed memory set at 4 bytes of Value range -2,147,483,648 through 2,147,483,647. Hence, an integer can be directly stored within fixed memory, or on the Stack. Alternatively, a String does not have a pre-defined memory size and it depends on implementing platform (the value range may 0 to approximately 2 billion Unicode characters), so it requires dynamic memory allocation. When a String object is created, the actual value is stored within dynamic memory, or on the Heap.

Note: The maximum string length will depend on your machine's architecture and memory allocation situation, but the String.Length property is a 32-bit integer, so there's an effective upper bound of Int32.MaxValue.

Stack and Heap

infosys interview questions and answers

Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM. Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled. More about.... Stack and Heap

Value Type and Reference Type

The Types in .NET Framework are either treated by Value Type or by Reference Type. A Value Type holds the data within its own memory allocation and a Reference Type contains a pointer to another memory location that holds the real data. More about.... Value Type and Reference Type

Is String in .Net immutable ?

Multinational company interview questions

Yes, the String in .Net is immutable. The System.String class is an immutable type provided in the .NET framework class library. Since a String is an immutable type, it cannot be modified. More about.... String immutable







net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.