As you can see in my code down below, I have A and B. For example if I place the result at B then it sometimes return as result=0, nothing prints out in the console. But A works as it is expected to do. I don't really understand it, I did put a breakpoint, and stepped into the code but it didn't tell me much, just that the result return 0, this should infact print out the movie at Index 0? Sorry for being stupid, just want some clarification.
private static void PickRandomMovie(List<Movie> movie)
{
var rng = new Random();
//A:
var result = rng.Next(0, movie.Count);
for (int i = 0; i < movie.Count; i++)
{
//B:
//var result = rng.Next(0, movie.Count);
if (movie[i].Index.Equals(result))
{
Console.WriteLine(movie[i].Title);
break;
}
}
}
private static List<Movie> AddMovie()
{
return new List<Movie>
{
new Movie(new Movie(0, "Shark Attack", "Horror, Thriller")),
new Movie(new Movie(1, "Tom Clancy's", "Action")),
new Movie(new Movie(2, "American Pie", "Comedy")),
new Movie(new Movie(3, "Ted", "Comedy")),
new Movie(new Movie(4, "Ted 2", "Comedy")),
new Movie(new Movie(5, "American Pie 2", "Comedy")),
new Movie(new Movie(6, "Tom Clancy's 2", "Action")),
new Movie(new Movie(7, "Guardians of the Galaxy", "Comedy, Action")),
};
}