Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do we achieve encapsulation in c#?

907


Is type nullable c#?

895


How do I automate my desktop application?

962


What is dll in vb.net?

907


What is an abstract class c#?

860


Explain the term inheritance in C#.

921


Overloaded constructor will call default constructor internally?

1002


What are handlers in c#?

929


What is the purpose of ienumerable in c#?

953


Enlist all the components of an ado.net framework?

841


What is the advantage of constructor?

856


What is the difference between new and override in c#?

964


I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?

929


What is difference between the "throw" and "throw ex" in .net?

906


Which is faster hashtable or dictionary?

930