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

Why do we use ienumerable in c#?

819


What is public or shared assemblies ?

949


Why do we use class in c#?

874


What is the do while loop code?

873


What is a console operator?

842


Is for loop faster than foreach?

949


Explain the difference between user control and custom control. Also, explain their use.

1013


Is c# a technology?

854


How can encapsulation be achieved?

1042


How do I create a multi language, multi file assembly?

990


How do I know if executenonquery is successful c#?

787


What is uint c#?

850


What is the difference between package and interface?

871


What is the use of getcommandlineargs() method in c#.net?

922


Which is executed if an exception has not occurred?

903