Is C# Object
/object
a value-type or reference type?
I examined that they can keep references but this references can't be used to change objects.
using System;
class MyClass
{
public static void Swap(Object obj1, Object obj2)
{
Console.WriteLine("After Swapping");
obj1 = 100;
obj2 = 200;
}
}
class MainClass
{
static void Main(string[] args)
{
Object obj1 = new Object ();
obj1 = 10;
Object obj2 = new Object ();
obj2 = 20;
Console.WriteLine(obj1.ToString());
Console.WriteLine(obj2.ToString());
MyClass.Swap(obj1, obj2);
Console.WriteLine(obj1.ToString());
Console.WriteLine(obj2.ToString());
Console.ReadLine();
}
}