I assume you want to check that movie type is one of the strings in the list...
Use
List<T>.Contains(T)[
^] method...
if (fType.Contains(movie.Type))
{
}
[Edit: Matt T Heffron]
If the
fType
is not very short, then this can be optimized using a
HashSet<string>
:
public List<Movie> mType(List<string> fType)
{
List<Movie> fMovie = new List<Movie>();
HashSet<string> typesMap = new HashSet<string>(fType);
foreach(Movie movie in ListOfMovies)
{
if (typesMap.Contains(movie.Type))
{
fMovie.Add(movie);
}
}
return fMovie;
}
And using Linq this would be:
public List<Movie> mType(List<string> fType)
{
HashSet<string> typesMap = new HashSet<string>(fType);
return (from movie in ListOfMovies where typesMap.Contains(movie.Type) select movie).ToList();
}