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 are console applications used for?
Can non-default constructors be used with single call sao?
What is a Managed Code??
What is difference between private, protected, and public in C#?
Can a static class have a constructor c#?
Can derived classes have greater accessibility than their base types?
Can the nested class access, the containing class. Give an example?
What is the purpose of c#?
What is eager loading in c#?
What is a thread? What is multithreading?
What is the benefit of interface in c#?
What is the difference between first and firstordefault?
How do you remove white spaces from a string?
Where is c# compiler located?
How do you pronounce c#?