Autor Beitrag
MysteryEskimo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN Xp
Visual C# Studio 2005
BeitragVerfasst: So 15.11.09 21:41 
if (t[i][i2] == 'a')
kosten += h[0] * i2;

Ich habe einen string[] Array und möchte auf ein Zeichen eines strings zugreifen.
Wo könnte der Fehler liegen?
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: So 15.11.09 21:49 
Welchen Fehler hast du denn? ;)
Erst mal dürfte es schwer sein, ein Char mit irgendetwas zu multiplizieren, du müsstest also auf jeden Fall erst den Char in ein int oder soetwas umwandeln. Das kannst du im Übrigen über die Convert-Klasse machen.

Fabi
MysteryEskimo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN Xp
Visual C# Studio 2005
BeitragVerfasst: So 15.11.09 21:54 
Wie kommst du auf multiplizieren?
Wegen der Fehlermeldung schau ich nach.
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: So 15.11.09 21:56 
Naja, weil du halt ein "*" benutzt ;)

Fabi
MysteryEskimo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN Xp
Visual C# Studio 2005
BeitragVerfasst: So 15.11.09 21:57 
Ah, es liegt nicht an dem Codestück!

Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

Eine Null Reference Exception. Ich werde mal einen größeren Codeausschnitt kopieren:

static double BerechneKosten(double[] h, string[] t)
{
double kosten = 0;
for (int i = 0; i < 8; i++)
{
for (int i2 = 0; i2 < t.Length; i++)
{



if (t[i][i2] == 'a')
kosten += h[0] * i2;
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: So 15.11.09 21:58 
Benutze doch bitte beim Posten von Code den C#-Code-Button, dann kann man das besser lesen. Geht auch über die Edit-Funktion noch ;)
Debug doch mal da rein und prüfe ob die beiden Arrays nicht null sind oder gar deren Inhalt.

Fabi
MysteryEskimo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN Xp
Visual C# Studio 2005
BeitragVerfasst: So 15.11.09 22:04 
h ist ein Array von double-Werten
Und den Fehler hab ich gefunden. Tippfehler bei der Array-Zuweisung.