public static Spel[] sökSpelViaTitel(string sökfras) { Spel[] hittadeSpel = new Spel[spelInfo.Length]; int spel = 0; for (int i = 0; i < spelInfo.Length; i++) { if (spelInfo[i].titel.ToLower().Contains(sökfras.ToLower()) || spelInfo[i].genre.ToLower().Contains(sökfras.ToLower())) { hittadeSpel[spel++] = spelInfo[i]; } } Spel[] hittadeSpelTrimmadVektor = new Spel[spel]; for (int i = 0; i < spel; i++) { hittadeSpelTrimmadVektor[i] = hittadeSpel[i]; } return(hittadeSpelTrimmadVektor); }
public static void LaddaInTitlar() { StreamReader infil = new StreamReader("SPEL.txt"); string rad = infil.ReadLine(); while (rad != null) { string[] fält = rad.Split('\t'); Spel game = new Spel(); game.titel = fält[0]; game.genre = fält[1]; game.betyg = int.Parse(fält[2]); spelInfo = LäggTillSpelTillOrginalVektorn(spelInfo, game); rad = infil.ReadLine(); } infil.Close(); }