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 |
How do I type a whitespace character?
What is method in c#?
What is autopostback in c#?
What is difference between c and c sharp?
What are handlers in c#?
What is get set in c#?
What is ado c#?
Can you inherit from multiple classes in c#?
Trace the O/p for a program on inheritance and Polymorphism. 3 classes A,B,C A with two methods public virtual SomeMethodA public virtual SomemoreMethodA B:A overide SomeMethodA C:B new Method SomeMethodA override SomeMoreMethodA main method { b new instance of B b.SomeMethodA b.SomeMoreMethodA b1 new instance of C b1.SomeMethodA b1.SomeMoreMethodA }
Distinguish between array and arraylist in c#?
1) how to delete duplicate records from table in sql server 2005 2) what is run time polymorphism
What is a partial method?
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)