Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c# List<int> in class

Name: tt 2011-03-05 12:18

So i made a class and put a public List<int> in there. Seems like every element in that class is using the same list. Even though i have new list() in the constructor.

Can anybody help?

Name: Anonymous 2011-03-05 12:28

>>15
notacija temp = new notacija(0, 1, 2);
            Notacija.Add(temp);
            Notacija.Add(temp);
            Notacija[0].pot.Add(1);
            Notacija[1].pot.Add(2);
            int stevec = 0;
            string ss = "";
            for (int b = 0; b < Notacija.Count; b++)
            {
                ss = "";
                for (int a = 0; a < Notacija[b].pot.Count; a++)
                {
                    ss += Notacija[b].pot[a] + " ";
                }
                MessageBox.Show(stevec + " " + ss);
            }


You can paste the class and use this if you want to see the problem if not let me explain:
Notacija is a list of notacija, so i add 2 object to it. Then i add to the List pot in the first object the number 0 and in the second object the number 2.

When i write out the List pot of every object it is like i added both numbers to both lists

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List