Is string reference type / value type?
Answers were Sorted based on User's Feedback
Answer / guest
Simple types (such as float, int, char), enum types and
struct types are all value types.
Note that many types (such as string) appear in some ways
to be value types, but in fact are reference types. These
are known as immutable types
| Is This Answer Correct ? | 18 Yes | 0 No |
Answer / ravikiran gullapalli
String is 100% Reference Type. It is an immutable object.
| Is This Answer Correct ? | 18 Yes | 0 No |
Answer / mukkamalla prasastha
if u dont know dont confuse others
String is 100 % reference type
| Is This Answer Correct ? | 17 Yes | 0 No |
Answer / k.hemalatha
string is a reference type but behave likes value type.
| Is This Answer Correct ? | 16 Yes | 2 No |
string is reference type . dont confuse yar..........
because String is immutable objects..........
means does not change the values(string).......
| Is This Answer Correct ? | 14 Yes | 2 No |
Answer / n
Hi Guys
If any of you got so far.. Here is the deal:
The differnce between value types and reference types are
whether the information is stored in the stack or on the
heap. Design guidelines for designing structures (value
type, stored in the stack) is that it's instance value
should be less than 16 bytes.
In the .NET Framework, ALL value types are 16 bytes or
shorter.
A string can be a lot more than 16 bytes...
It does however act like a value type in order to make the
programming easier for us... This can be the reason for all
this confusion...
Now stop arguing and start converting coffee into code....
/N
| Is This Answer Correct ? | 14 Yes | 2 No |
Answer / akn
Everything not derived from System.ValueType is a reference
type.
So System.String is reference type.
| Is This Answer Correct ? | 11 Yes | 0 No |
Answer / ak
How do you explain this then?
public void MyTest()
{
Program myClass = new Program();
myClass.value = 1;
Console.Out.WriteLine(myClass.value.ToString
()); //1
Program newClass = myClass;
newClass.value = 2;
Console.Out.WriteLine(myClass.value.ToString
()); //2
myClass.strvalue = new String("1".ToCharArray
());
Console.Out.WriteLine(myClass.strvalue); //1
newClass.strvalue = myClass.strvalue;
newClass.strvalue = "2";
Console.Out.WriteLine(myClass.strvalue); //2
}
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / n.
There is no magic.... You can test all the types:
using System;
using System.Collections.Generic;
using System.Text;
namespace List_Value_Types
{
class Program
{
static void Main(string[] args)
{
SByte a = 0;
Byte b = 0;
Int16 c = 0;
Int32 d = 0;
Int64 e = 0;
string s = "";
Exception ex = new Exception();
object[] types = { a, b, c, d, e, s, ex};
foreach (object o in types)
{
string type = "";
if (o.GetType().IsValueType)
type = "Value type";
else
type = "Reference type";
Console.WriteLine("{0}: {1}", o.GetType(),
type);
}
Console.ReadKey();
}
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
What?s a multicast delegate?
Is object an int c#?
What is visual c# net?
What is ulong in c#?
What is difference between comparable and comparator?
The int maps to which C# keyword in .NET type?
What are static and dynamic variables?
Explain the difference between passing parameters by value and passing parameters by reference with an example?
If I want to override a method 1 of class A and in class b then how do you declare ?
What is alias in c#?
What are get and set in c#?
What is an Interface in C#?
0 Answers TryTechnicals Pvt Ltd,
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)