Is string reference type / value type?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
Answer / praseetha sandeep
100% sure string is reference type....
Is This Answer Correct ? | 1 Yes | 0 No |
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 |
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 |
Explain About disco and uddi
How to transpose rows into columns and columns into rows in a multi-dimensional array?
What is an inheritance in c#?
What is regex replace in c#?
What is ENUM?
10 Answers TCS, Wipro, YeshTech,
What is array and arraylist?
Can we declare private class in c#?
Why delegates are type safe in c#?
What are interfaces in c#?
What?s class SortedList underneath?
I want to print "Hello" even before main() is executed. How will you achieve that?
What is the difference between Abstract and Interface?
22 Answers Agile Software, FER, HCL, Sys Universe,