Problem with list

Hi, ran on this silly problem, if I change list.count of Test1 to 5, when runing game both Test1.count and Test2.count in inspector become 4. This is simple version of code where i ran on this problem.
Why is not only Test2 chaning count.

    public List<int> Test1;
    public List<int> Test2;

 
    void Start ()
    {
        Test2 = Test1;
         Test2.Remove(Test2[Test2.Count - 1]);
    }

Because this is a shallow copy, this means, you copy the reference, you don’t duplicate it
To solve this, do new List(Test1);

Test2 = Test1. List are reference types. You’re not copying the list, you’re setting Test2 to point to Test1. They both are the same referenced list.

@gorbit99 beat me to it. :slight_smile:

Just found answer, but thanks and sory for stupid question.