Привет У меня есть некоторые сомнения в распределении памяти ссылочных типов. Пожалуйста, уточните мои вопросы, которые комментируются между приведенным ниже кодом.Как память выделяется для ссылочных типов в C#?
class Program
{
static void Main(string[] args)
{
testclass objtestclass1 = new testclass();
testclass objtestclass2 = new testclass();
testclass objtestclass3 = new testclass();
// Is seperate memory created for all the three objects that are created above ?
objtestclass1.setnumber(1);
objtestclass2.setnumber(2);
Console.Write(objtestclass1.number);
Console.Write(objtestclass2.number);
objtestclass3 = objtestclass1;
//When we assign one object to another object is the existing memory of the objtestclass3 be cleared by GC
Console.Write(objtestclass3.number);
objtestclass3.setnumber(3);
Console.Write(objtestclass3.number);
Console.Write(objtestclass1.number);
Console.Read();
}
public class testclass
{
public int number = 0;
public void setnumber(int a)
{
number = a;
}
}
Спасибо.
Привет, Jon, спасибо за ваш ответ. Я с гордостью могу сказать, что я ваш фанат :) – Jebli