I have the following code:
public class Test
{
public static void Main()
{
List<Person> list = new List<Person>();
Person person = new Person() { Name="Chris" };
list.Add(person);
person = new Person(){ Name="Wilson the cat" };
list.Add(person);
Console.WriteLine(list[0].Name);
Console.WriteLine(list[1].Name);
Console.ReadLine();
}
}
public class Person
{
public string Name {get;set;}
}
My question is where does the first person instance go? Does the CLR magically create a new instance of it somewhere? Is there anyway of referencing it outside of the list - e.g. where does it go after the method has completed? What method is used for storing objects in a collection (that was 4 questions).