Is string reference type / value type?

Answers were Sorted based on User's Feedback



Is string reference type / value type?..

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

Is string reference type / value type?..

Answer / ravikiran gullapalli

String is 100% Reference Type. It is an immutable object.

Is This Answer Correct ?    18 Yes 0 No

Is string reference type / value type?..

Answer / mukkamalla prasastha

if u dont know dont confuse others
String is 100 % reference type

Is This Answer Correct ?    17 Yes 0 No

Is string reference type / value type?..

Answer / k.hemalatha

string is a reference type but behave likes value type.

Is This Answer Correct ?    16 Yes 2 No

Is string reference type / value type?..

Answer / abhit

String is reference type.

Is This Answer Correct ?    14 Yes 1 No

Is string reference type / value type?..

Answer / kapil dalke

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

Is string reference type / value type?..

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

Is string reference type / value type?..

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

Is string reference type / value type?..

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

Is string reference type / value type?..

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

Post New Answer

More C Sharp Interview Questions

Can you mark static constructor with access modifiers?

0 Answers  


What are the Types of configuration files and their differences

0 Answers   BirlaSoft,


Explain the accessibility modifier protected internal?

0 Answers  


what is meant inheritance. can you exaplain what kind inhertance ussed in your project

1 Answers  


What is uint64?

0 Answers  






Explain hash table in c# ?

0 Answers  


What is the C# syntax to catch any possible exception?

0 Answers   Siebel,


can you tell me what are the steps should follow to do delay signing.

1 Answers   HCL,


What does addressof operator do in background ?

0 Answers  


Define parsing? Explain how to parse a datetime string?

0 Answers  


What are the Types of caching

0 Answers   TCS,


Explain the difference between passing parameters by value and passing parameters by reference with an example?

0 Answers  


Categories