我在做一个小项目,用户在一个数组中输入关于一部电影的信息,然后可以搜索标题,找出之前输入的信息。但是,我当前的搜索函数在代码末尾返回:
System.String[]'s age rating is System.Int32[]
System.String[]'s genre is System.String[]
System.String[]'s rating is System.Int32[]
我如何让代码加载所需的信息,而不是它当前返回的信息?请参见下面的代码。
static void Movie(string[] MovieTitle, string[] Genre, int[] AgeRating, int[] Rating)
{
for (int i = 0; i < Rating.Length; i++)
{
Console.WriteLine("What is the title of the movie?");
MovieTitle[i] = (Console.ReadLine());
Console.WriteLine("What is the age rating of the movie?");
AgeRating[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What is the genre of the movie?");
Genre[i] = (Console.ReadLine());
Console.WriteLine("What is the user rating of the movie?");
Rating[i] = Convert.ToInt32(Console.ReadLine());
}
}
static void Main()
{
string[] MovieTitle = new string [5];
int[] AgeRating = new int [5];
string[] Genre = new string [5];
int[] Rating = new int [5];
int position;
string search;
Movie(MovieTitle, Genre, AgeRating, Rating);
Console.WriteLine("What movie do you want to see?");
search = Console.ReadLine();
position = Array.IndexOf(MovieTitle, search);
Console.WriteLine(MovieTitle + "'s age rating is " + AgeRating);
Console.WriteLine(MovieTitle + "'s genre is " + Genre);
Console.WriteLine(MovieTitle + "'s rating is " + Rating);
}
}
}
null
Console.WriteLine(MovieTitle[position] + "'s age rating is " + AgeRating);
Console.WriteLine(MovieTitle[position] + "'s genre is " + Genre);
Console.WriteLine(MovieTitle[position] + "'s rating is " + Rating);