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 the difference between returning iqueryable vs ienumerable?

453


Is the following code legal?

567


What is tryparse?

519


What is a nested type. Give an example?

620


What is xamarin used for?

510






What is c# console application?

484


windows c# using datagridview in edit form sql server

3575


What is entity framework in c#?

476


Can you specify nested classes as partial classes?

512


How do you comment out code in c#?

460


How many types of constructor are there in c#?

484


write a C# Program add two matrix ?

576


What is cli in c#?

500


Why cannot you specify the accessibility modifier for methods inside the interface?

494


What is difference between ienumerable and list?

517