Regarding the following code:
main()
List<int> a = new List<int>();
List<int> b = new List<int>();
a.Add(2);
a = add(a, 3);
b = add(a, 4);
b.Add(5);
a.Add(6);
function
static List<int> add(List<int> l, int x)
{
l.Add(x);
return l;
}
What I would like is that the result would be: a(2,3,6) and b(2,3,4,5).
In the end, both lists contain (2,3,4,5,6).
I understand that this may happens because a,b are just pointers to the start of the list. How could i achieve my desired result?