Is string reference type / value type?

Answers were Sorted based on User's Feedback



Is string reference type / value type?..

Answer / charlie

In this part of the C# docs, a string is explicitly named
as a reference type:

http://msdn.microsoft.com/en-us/library/490f96s2.aspx

Is This Answer Correct ?    3 Yes 0 No

Is string reference type / value type?..

Answer / sunil

string is a 1000% reference type

Is This Answer Correct ?    3 Yes 0 No

Is string reference type / value type?..

Answer / kris cassidy

I am so much better than all of you a string is an
amalgomation of cotton and wool, not to be confused with
cotton wool, strings irregular cousin!

Is This Answer Correct ?    3 Yes 0 No

Is string reference type / value type?..

Answer / frank

This is the stupidest thread I've seen in many years of surfing the internet, and the stupidest discussion I've witnessed in even more years of software development. All you value type string proponents should start your own club and go hang out with the flat earth society.

Is This Answer Correct ?    2 Yes 0 No

Is string reference type / value type?..

Answer / mathew

I am confused,
Microsoft in one site says "String is a reference type".
Check the below website
http://msdn.microsoft.com/en-us/library/362314fe.aspx
It says
"Although string is a Reference type, the equality
operators (== and !=) are defined to compare the values of
string objects, not references. This makes testing for
string equality more intuitive".

while when checked the other website
http://msdn.microsoft.com/en-us/library/83fhsxwc.aspx
Which list's "Built-In Types Table (C# Reference)" which has
STRING in the list

C# Type .NET Framework Type
--------- ---------------------
bool System.Boolean
byte System.Byte
sbyte System.SByte
char System.Char
decimal System.Decimal
double System.Double
float System.Single
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
object System.Object
short System.Int16
ushort System.UInt16
string System.String

And it is mentioned
"All of the types in the table, except OBJECT and STRING,
are referred to as simple types."

From all these I infer that "STRING is a reference type".

Is This Answer Correct ?    2 Yes 0 No

Is string reference type / value type?..

Answer / rachel p

The above code sample doesn't prove anything, except that
Malli's code is full of bugs! You've a line in there that
contains the following error:

Console.WriteLine("StrName1=" + StrName2);

for goodness sake! And that's by no means the only error in
logic/reasoning.

String *is* a Reference Type, however, for many of the good
reasons established by previous answers.

Is This Answer Correct ?    1 Yes 0 No

Is string reference type / value type?..

Answer / arun

String is REFERENCE TYPE

Is This Answer Correct ?    1 Yes 0 No

Is string reference type / value type?..

Answer / praseetha sandeep

100% sure string is reference type....

Is This Answer Correct ?    1 Yes 0 No

Is string reference type / value type?..

Answer / guru dayal roy

String is reference type. When we define a string and
initialise it creats an object and again when we try to
append something it creates a new object which contains
both the string togather. So since string initialization
creates an object we can say string is also reference type
which does not happen with other value types.

Is This Answer Correct ?    1 Yes 0 No

Is string reference type / value type?..

Answer / 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

More C Sharp Interview Questions

What?s a satellite assembly?

1 Answers  


public void A() { int x; x = 8; x *= 4 + 8 / 2; } Given the above code, what is the value of "x"?

8 Answers  


What is the default value of singleordefault?

0 Answers  


What is the difference between iqueryable and ienumerable?

0 Answers  


What are the properties of a string class?

0 Answers  






How to make a class non-inheritable other than sealed?

7 Answers  


What is multicast delegate in c# ?

0 Answers  


What is difference between a function and a method?

0 Answers  


I have a class declared as below public class a { public void add() {} } What is the diference between a a1 =new a; and simply a a1;

3 Answers  


If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?

0 Answers  


What is an escape sequence in c#?

0 Answers  


What is default constructor in c#?

0 Answers  


Categories