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
What does readonly mean in c#?
What is xor operator in c#?
What are the types of parameters in c#?
Why do we use lambda expression in c#?
Is string nullable c#?
Can constructor be protected in c#?
What is inheritance c#?
What does using do in c#?
What is ado c#?
Is stringbuilder better than string?
How do you sort an array in c#?
How long will it take to learn c sharp?
Explain the functionalities of satellite assembly?
What do you mean by object pooling?
What is eager and lazy loading in c#?