For example i have the following class:
class Person
{
    public List<int> Grades{ get; set; }
    public Person(List<int> grades)
    {
        this.Grades = grades;
    }
}
And than i use this class in a main method , something like:
    static   void Main(string[] args)
    {
        List<int> grades = new List<int> { 1, 2, 3, 4, 5 };
        Person person = new Person(grades);
        for (int i = 0; i < 5; i++)
        {
            if (i % 2 == 0)
            {
                grades[i] = 0;
            }
            else
            {
                grades[i] = -1;
            }
        }
        foreach(var grade in person.Grades)
        {
            Console.Write(grade + " ");
        }
        Console.ReadKey();
    }
After running this code i expected to have on console the: 1 2 3 4 5 output result. Insteead i have this output result: 0 -1 0 -1 0
I expected that the collection "saved" into Person instance to stay how it was initialized. What should i do to keep this collection unmodified for Person instances, so that i will have the "1 2 3 4 5" output result even if i modify the grades collection in main method.
Can someone please explain me, why is this happening ?
 
     
     
     
     
    