Answer the question
In order to leave comments, you need to log in
Use of one variable by several objects. How does this happen?
Hi all!
using System;
namespace ConsoleApp1
{
class AppObject
{
static int Main()
{
People humanoid_1 = new People("Name1");
People humanoid_2 = new People("Name2");
humanoid_1.peopleMetod();
humanoid_2.peopleMetod();
return 0;
}
}
class People
{
string humanoid_name;
public People(string name)
{
humanoid_name = name;
}
public void peopleMetod()
{
Console.WriteLine(humanoid_name);
}
}
}
Answer the question
In order to leave comments, you need to log in
I don't understand how 2 different values are written to one variable
People humanoid_1 = new People("Name1"); // humanoid_1 -> переменная раз
People humanoid_2 = new People("Name2"); // humanoid_2 -> переменная дваз
People
. People
. Reference types are stored on the heap. And when you create an object of a reference type , a reference to the address on the heap is placed on the stack.
Main tobish: you have two heaps) People humanoid_1 = new People("Name1");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question