Autor Beitrag
Ivy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 20.04.11 12:01 
Hey,
ja der titel sagt eigentlich schon fast alles, ich habe eine liste erstellt:

ausblenden C#-Quelltext
1:
2:
List<FehlerInfo> Fehler = new List<FehlerInfo>();
Fehler.Add(new FehlerInfo(StepNr, StepName, Counter));


in die daten aus einer dataview eingetragenw erden. jetzt soll aber nur eine neue liste angelegt werden wenn es den datensatz noch nicht gibt. wie kann ich das prüfen? mit exist?

danke
lg
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 20.04.11 12:44 
Ja, ist ein Weg. Was ist denn deine Definition von gleichen Fehlerinfo Objekten? Nur dann kann man ja eine gültigen Ausdruck für die Exists Abfrage ermitteln.
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 20.04.11 13:09 
ja wenn die StepNr schon existiert dann soll kein neuer datensatzangelegt werden.
wie funktioneirt das dann mit exists
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 20.04.11 13:28 
Alle Einträge durchgehen und nachschauen. ;-)
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Mi 20.04.11 13:48 
Oder ein Dictionary verwenden und StepNr als Key.
Dann mit ContainsKey abfragen.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 20.04.11 13:56 
Ich würde auch eher für ein Dictionary oder eine SortedList plädieren.

Mit List<T> und Exists ginge es etwa so

ausblenden C#-Quelltext
1:
2:
3:
Fehlerinfo info = new FehlerInfo(StepNr, StepName, Counter);
if (!Fehler.Exists(x => x.StepNr == info.StepNr))
    Fehler.Add(info);