public HashSet<Student> GetStudents(int studentId)
{
IEnumerable<Student> studentTypes = this.studentTypes .Where(x => (x.studentID== studentId));
if (studentTypes .FirstOrDefault() != null)
{
//return new HashSet<Student>(studentTypes);
return studentTypes.ToHashSet();
}
else
{
return new HashSet<Student>();
}
}
public static class LinqUtilities
{
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> enumerable)
{
HashSet<T> hashSet = new HashSet<T>();
foreach (var en in enumerable)
{
hashSet.Add(en);
}
return hashSet;
}
}
Questa funzione è chiamata sacco di volte dire 1000 volte e ci sono 5000 studenti nel set di risultati. Come ottimizzare questa funzione ... So che la conversione da IEnumerable
a HashSet
sta causando un sacco di spese generali. ToHashSet
è il mio metodo di estensione. Questa funzione rallenta e consuma molto tempo.Ottimizzare IEnumerable a HashSet conversione in LINQ
Che cosa fa ToHastSet? – Turbot
aggiunto aHashSet ... l'hashset è un codice da Internet. – abbas