Autor Beitrag
qwertz123
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Fr 24.04.09 09:49 
Hallo Leute, folgendes Problem liegt vor.

Ich erzeuge eine Liste, die aussieht wie ein Vektor. Der Vektor füge ich zu einer weiteren Liste hinzu, in der alle Vektoren gespeichert werden sollen (also eine Liste von einer Liste).
Mit der ersten Liste möchte ich verschiedene Vektoren erzeugen. Sobald ich den Vektor aber ändere, ändert sich dies in der Liste mit (in der die Vektoren gespeichert werden. Ich möchte mit den Vektoren herumhantieren, ohne dass diese sich jeweils in der Liste ändern.
Nachstehend ein Auszug meine Quellcodes: Aggregation beschreibt eine Liste. Die Liste besteht aus den Zuständen OK,DD,DU,SD,R.


ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
        AddStateToList(aggregation);
        RemoveLastState(aggregation);



        public void AddStateToList(List<Aggregationszustand> aggr)
        {
            List<Aggregationszustand> hilfsaggregation = new List<Aggregationszustand>();
            hilfsaggregation = aggr;
            aggregationlist.Add(hilfsaggregation);
        }


        public void RemoveLastState(List<Aggregationszustand> aggr)
        {
            model.actualchannelcount = model.actualchannelcount - 1;
            aggr.RemoveAt(aggregation.Count - 1);
        }




    public enum Aggregationszustand
    {
        OK,
        SD,
        DD,
        DN,
        R
    }


        private List<Aggregationszustand> _aggregation = new List<Aggregationszustand>();
        private List<List<Aggregationszustand>> _aggregationlist = new List<List<Aggregationszustand>>();

        public List<Aggregationszustand> aggregation
        {
            get
            {
                return this._aggregation;
            }
        }
        public List<List<Aggregationszustand>> aggregationlist 
        {
            get
            {
                return this._aggregationlist;
            }
        }
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Fr 24.04.09 10:31 
Hallo,

sehr komischer Konstrukt den du da aufgesetzt hast. Mit der Deklaration der _aggregationList hast du doch schon eine Liste von einer Liste von Aggregationszuständen. Mehr brauchst du nicht, musst du nur noch die Liste befüllen.

Gruß Daniel
qwertz123 Threadstarter
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Fr 24.04.09 10:53 
das mit Hilfsaggregation (Zeile 8 und 9) kann ich mir sparen. Stimmt.

Sobald ich aber "aggr" ändere, ändert sich alles in der Liste "aggregationlist" mit. Das soll nicht sein.
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Fr 24.04.09 11:06 
Ja weil du die Referenzen zuweißt, dann werden spätere Änderungen mitübernommen. Ich vermute du suchst nach sowas:

ausblenden C#-Quelltext
1:
2:
3:
4:
        public void AddStateToList(List<Aggregationszustand> aggr)
        {
            aggregationlist.Add((List<Aggregationszustand>) aggr.Clone());
        }
qwertz123 Threadstarter
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Fr 24.04.09 11:50 
Super. Funktioniert. Ich klone einfach "aggr". dann passts

Danke!!