Is string reference type / value type?
Answer Posted / pradeep chouhan
Hi Friends,
string is a reference type.
kindly go through below code.
string str1 = "1";
Response.Write(str1+"<br/>"); //output: 1
string str2 = str1;
str2="2";
Response.Write(str1+"<br/>"); //output: 1 (instead of 2)
Bcos of this behavior of string most of the people think
string is a value type. but the actual mystery lies on the
3rd line of the above code ie string str2 = str1; Always
remember '=' assignment operator is overloaded by default
for string. so when str2 = str1 this means a copy of str1 is
assigned to str2 instead of its reference.
I think now the idea is clear.
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
if you do have a stack overflow profile.what is your ranking?
What is oledb in c#?
What does clr stand for?
Why generics are used?
Can we have only “try” block without “catch” block in c#?
What is c# console application?
Why do we use reflection in c#?
What is the difference between a field and a property in c#?
What is difference between dictionary and hashtable in c#?
In a C# class we have a SortedList member m_addinProjects
we want to provide an iterator to allow the consumer of
this class access to the items in the collection. Please
provide an iterator method for the AnalyzeAddinsDLL class
below and an example of how it would be used.
namespace AnalyzeAddinsDLL
{
public class AllAddInProjects
{
private SortedList
What is difference between web and window application?
What is difference between array and list in c#?
What is scaffolding in c#?
Explain the difference between a namespace and assembly name in .net?
What is the difference between early binding and late binding in c#?