1
A very basic doubt, but it’s bugging my head.
I have the following code snippet:
A class that receives a list as a parameter in the constructor:
public class MinhaClasse
{
IList<int> Items;
public MinhaClasse(IList<int> Items)
{
this.Items = Items;
}
// Aqui eu tenho um método que manipula a propriedade Items
public void MeuMetodo()
{
Items[0] = 1+1;
}
}
When I’m going to instantiate the class, I create the list, pass it as parameter and call the "MeuMetodo()" which changes the value of the first Item in my list from '0' to '2':
IList<int> items = new List<int>(){ 0 };
GildedRose app = new GildedRose(items);
app.MeuMetodo();
// A minha dúvida acontece aqui, pois continuo tendo acesso a lista de items, mas no novo estado, após a alteração pelo método da minha classe
Console.WriteLine(items[0]); // Essa linha imprime o valor '2' e não o valor '0' que é o valor atual da minha lista criada aqui
To have access to the value '2' I would not have to create a "Get" within the "MinhaClasse" to return the "Items" property? Why did you continue to have access to the same value as my class property after calling the "MeuMetodo()"?
Killed! Thank you very much!!
– Jaderson