public static void ReadRatings( User[] users, Movie[] movies, string path ) { using( TextReader r = File.OpenText( path ) ) { string line; while( (line = r.ReadLine()) != null ) { string[] cells = line.Split( CellSeparator, StringSplitOptions.None ); int idUser = int.Parse( cells[0] ); int idMovie = int.Parse( cells[1] ); if( idMovie >= 0 && idMovie < movies.Length && idUser >= 0 && idUser < users.Length ) { users[idUser].Ratings.Add( movies[idMovie], int.Parse( cells[2] ) ); } } } }
public static void ReadMovies( string path, out Dictionary<int, Movie> first, out Dictionary<int, List<Movie>> duplicates ) { first = new Dictionary<int, Movie>(); duplicates = new Dictionary<int, List<Movie>>(); using( TextReader r = File.OpenText( path ) ) { string line; while( (line = r.ReadLine()) != null ) { Movie exists, u = new Movie( line ); if( first.TryGetValue( u.MovieID, out exists ) ) { List<Movie> list; if( !duplicates.TryGetValue( u.MovieID, out list ) ) { list = new List<Movie>(); duplicates.Add( u.MovieID, list ); } list.Add( u ); } else first.Add( u.MovieID, u ); } } }