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 a virtual property. Give an example?

744


What are the principles of delegation?

734


If a child class instance is created, which class constructor is called first - base class or child class?

725


What happens during the process of boxing?

843


How to use reflection to call generic method?

691


What type is string in c#?

660


Why dependency injection is used in c#?

714


Why dictionary is used in c#?

742


Explain the 3 types of properties in c# with an example?

763


What is difference between float and integer?

811


What floating point types is supported in C#?

807


What is private protected in c#?

688


What framework is used for performance testing/load testing?

1729


Are c# destructors the same as c++ destructors?

794


Is concurrent queue thread safe?

710