Is string a value type or a reference type?

Answers were Sorted based on User's Feedback



Is string a value type or a reference type?..

Answer / gulrez alam

String is Referenced Type and stored in the Heap....

Is This Answer Correct ?    55 Yes 2 No

Is string a value type or a reference type?..

Answer / vidhya t

Reference Type

Is This Answer Correct ?    46 Yes 6 No

Is string a value type or a reference type?..

Answer / tarun kumar

String in .NET id 'Reference Type'.The reason is quite
simple.All classes in the .NET Environment are 'Reference
Type' & 'String' is a Class in .NET (not DataType as in VB
6.0)

Is This Answer Correct ?    40 Yes 5 No

Is string a value type or a reference type?..

Answer / benjamin janecke

String is a reference type but it behaves somewhat like a
value type. So it's a bit tricky and many developers don't
know it.

Great care should be taken when doing excessive string
manipulations with the String class. As already posted,
each String is read only and can never be changed. Thus,
every manipulation creates a new instance (and causes the
garbage collector to remove old ones) which can have a
dramatic performance impact on an application. Therefore,
always use the StringBuilder class in these scenarios,
which holds only one representation of a string in memory
and performs any changes directly to that memory block.

Btw. for those who don't belive String is a reference type,
just refer to MSDN or run ILDASM und load the mscorlib.dll
module from the .NET Framework. Then go to System.String
and u'll notice it's directly inherited from System.Object -
contrary to, for instance, the System.Byte class which is
inhertied from System.ValueType, meaning Byte is a value
type, String is not.

Is This Answer Correct ?    36 Yes 2 No

Is string a value type or a reference type?..

Answer / sheetal shivdas

run this code : to see that string is reference type


SByte a = 0;
Byte be = 0;
Int16 c = 0;
Int32 d = 0;
Int64 ee = 0;
String s = "";
Exception ex = new Exception();

object[] Types = { a, be, c, d, ee, s,ex };

foreach (object obj in Types)
{
string type;
if (obj.GetType().IsValueType)
type = "Value Type";
else
type = "Reference Type";
Response.Write(type);
}

Is This Answer Correct ?    32 Yes 5 No

Is string a value type or a reference type?..

Answer / senthilselvan

string is a reference type.

string str = "hello";
char x = str[1];

here what we do is handling the memory.
which type allows you to handle the memory is reference types.

Is This Answer Correct ?    26 Yes 1 No

Is string a value type or a reference type?..

Answer / albn

String is a reference type. If two string variable has the
same string it stored in the same heap memory address.

eg in VB.Net
Dim a as string="Hello"
dim b as string="Hello"

both variable refer to same memory address. As strings are
immutable reference type you can't get the change in one
variable to another.

Is This Answer Correct ?    19 Yes 4 No

Is string a value type or a reference type?..

Answer / raj

Reference type
It create a new instance every time

Is This Answer Correct ?    7 Yes 2 No

Is string a value type or a reference type?..

Answer / kunal sobti

string is reference type not value type...

Is This Answer Correct ?    3 Yes 0 No

Is string a value type or a reference type?..

Answer / micho

Strings are reference types, but they are special reference
types because they are made to behave like value-types.
For instance, after assigning a string to another, the two
strings remain independent. Likewise, you compare strings
with the = operator (because it is overloaded).

You can open the MSDN and see that strings are classes (ie,
reference-types).

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

What is redirecting behavior?

0 Answers  


What kind of programming language is ASP.NET?

0 Answers   3i Infotech,


What is three major points in WCF?

9 Answers   Syntel,


You have been given the task of designing a web services to expose the data that is stored in a database on the server. In order to successfully build the web services, you need to import some namespaces. What is the minimum namespace you need to import? a) System.Web b) System.WebServices c) System.Web.Services d) System.Web.ServiceModel

2 Answers   Syntax Softtech,


code for "For every 5days system has to create 1text file with the corresponding date and it has to store in c-drive" by using web applications

0 Answers  






When maintaining session through sql server, what is the impact of read and write operation on session objects?

0 Answers  


Diff between web user control and web custom control?

0 Answers  


What is the use of web.config file?

0 Answers  


Describe the events in the life cycle of a web application.

0 Answers  


Difference b/w casting and boxing?

5 Answers   IBS,


One of the properties of the Web Part has an incorrect format. Windows SharePoint Services cannot deserialize the Web Part. Check the format of the properties and try again. - this error is occured in Sharepoint 2007 while deploy the web part

1 Answers   WebInfo,


How do you perform validations ?

2 Answers   Microsoft,


Categories