I'm beginner and looking for some help when trying to get this code working. "public override string ToString()" method shouldn't be touched as that is correct. But the code returns an error below. What I might be doing wrong?
Unhandled Exception: System.IndexOutOfRangeException: Array index is out of range. at Jumppa..ctor (System.String nimi, System.String[] ajat, System.String[] paikat) [0x00000] in :0 at Jumppa.Main (System.String[] args) [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Array index is out of range. at Jumppa..ctor (System.String nimi, System.String[] ajat, System.String[] paikat) [0x00000] in :0 at Jumppa.Main (System.String[] args) [0x00000] in :0
Using System;
using System.Collections.Generic;
class Jumppa
{
public override string ToString()
{
string jumppa = nimi+"\najat:\n";
for (int i=0; i < ajat.Length; i++)
{
jumppa+= ajat[i] + "\n";
}
jumppa += "\npaikat:\n";
for (int i=0; i < paikat.Length; i++)
{
jumppa+= paikat[i] + "\n";
}
return jumppa;
}
public string nimi;
public string[] ajat=new string[2];
public string[] paikat=new string[2];
public Jumppa(string nimi,string[] ajat,string[]paikat)
{
this.nimi = nimi;
this.ajat[2] = ajat[2];
this.paikat[2] = paikat[2];
}
public Jumppa jumppa(Jumppa J1)
{
return this;
}
static void Main(string[] args)
{
//System.Collections.ArrayList jumppa = new System.Collections.ArrayList();
Jumppa[] J1=new Jumppa[3];
J1[0] = new Jumppa ("junior",new[] {"Wedn 9:30", "Frid 9:30"},new[]{"Gym", "Basement"});
J1[1] = new Jumppa ("adult",new[] {"Wedn 10:30", "Frid 10:30"},new[]{"Gym", "Basement"});
J1[2] = new Jumppa ("oldlady",new[] {"Wedn 11:30", "Frid 11:30"},new[]{"Gym", "Basement"});
//jumppa.Add(J1);
//for (int i=0; i<2; i++)
//{
Console.WriteLine(J1[0].jumppa(J1[0]));
//}
return;
}
}