Hallo,
unten stehendes Programmfragment funktioniert nicht, d.h. es wird zu keinem Schlüssel ein Wert gefunden. Eine Implementierung mit einer ArrayList und sequentieller Suche lieferte hingegen die gewünschte Werte. Hat jemand einen Tip, wo der fehler liegen könnte ?
Gruß
Horst
struct ek_t {
public string Kuerzel;
public string KuerzelStr;
public decimal Preis;
}
//------------------------------------------------
class EssKuerzel {
private Hashtable ht;
private ek_t ek;
// Constructor
public EssKuerzel(string fn) {
try {
Hashtable ht = new Hashtable();
using (StreamReader sr = new StreamReader(fn)) {
string line;
string[] split = new string[3];
while ((line = sr.ReadLine()) != null) {
if (line.Length > 2) { // faengt Leerzeilen ab
split = line.Split(';');
ek.Kuerzel = split[0].Trim();
ek.KuerzelStr = split[1].Trim();
ek.Preis = Convert.ToDecimal(split[2]);
ht.Add(ek.Kuerzel, ek);
} // if
} // while
} // using
} catch (Exception ex) {
MessageBox.Show("... );
} // try ... catch
} // constructor
public ek_t Get(string k) {
try {
return (ek_t)ht[k];
} catch (Exception ex) {
MessageBox.Show("... );
ek.Kuerzel = String.Empty;
ek.KuerzelStr = String.Empty;
ek.Preis = 0.0M;
return ek;
}
} // GetEK
}
}
unten stehendes Programmfragment funktioniert nicht, d.h. es wird zu keinem Schlüssel ein Wert gefunden. Eine Implementierung mit einer ArrayList und sequentieller Suche lieferte hingegen die gewünschte Werte. Hat jemand einen Tip, wo der fehler liegen könnte ?
Gruß
Horst
struct ek_t {
public string Kuerzel;
public string KuerzelStr;
public decimal Preis;
}
//------------------------------------------------
class EssKuerzel {
private Hashtable ht;
private ek_t ek;
// Constructor
public EssKuerzel(string fn) {
try {
Hashtable ht = new Hashtable();
using (StreamReader sr = new StreamReader(fn)) {
string line;
string[] split = new string[3];
while ((line = sr.ReadLine()) != null) {
if (line.Length > 2) { // faengt Leerzeilen ab
split = line.Split(';');
ek.Kuerzel = split[0].Trim();
ek.KuerzelStr = split[1].Trim();
ek.Preis = Convert.ToDecimal(split[2]);
ht.Add(ek.Kuerzel, ek);
} // if
} // while
} // using
} catch (Exception ex) {
MessageBox.Show("... );
} // try ... catch
} // constructor
public ek_t Get(string k) {
try {
return (ek_t)ht[k];
} catch (Exception ex) {
MessageBox.Show("... );
ek.Kuerzel = String.Empty;
ek.KuerzelStr = String.Empty;
ek.Preis = 0.0M;
return ek;
}
} // GetEK
}
}
Comment