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 |
why C#.net doesnot support prcedures and why it supports structs,functions
Can we create multiple constructors?
What?s the .NET datatype that allows the retrieval of data by a unique key?
How does it work?
What?s the top .NET class that everything is derived from?
What is encapsulation in csharp?
Is string primitive?
Does c# support multiple class inheritance?
What do you understand by 'access specifiers' in C#?
List some Advantages of switch-case over if else?
When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?
What are sorted lists?