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

Define parsing?

515


Distinguish between continue and break statement?

576


What is xml comments in c#?

504


What is the difference between Static, Const and read only?

550


What is use of a HashTable in .NET?

714






What are the generation of Garbage Collection in C# .NET ?

565


What is dictionary collection in c#?

507


What are callback methods in c#?

513


How can I check the type of an object at runtime?

542


Can list contain duplicates c#?

495


What is ildasm and obfuscator in net?

551


What is the difference between IEnumerator and IEnumerable?

687


What is the use of table aliases?

500


How do I create a multi language, multi file assembly?

636


What do you mean by thread safe in c#?

475