Is string reference type / value type?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c# best for?

712


What are the various components in crystal reports?

716


Is string a class in c#?

652


What are primitive types in c#?

740


What are cshtml files?

668


How do I calculate relative time?

708


Explain async and await?

904


What is polymorphism and its types in c#?

655


What are the delegates in c#?

687


Define multicast delegate? How it be used?

787


What is a multicast delegate in c#?

762


Which is better python or c#?

646


How do you type a null character?

673


Why are mutable structs evil?

716


What is the difference between disposing of () and finalize() methods in c#?

755