Aller au contenu

Use cast instead of select (ARCH606)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.performance.use-cast-instead-of-select · Severity info · Category performance

A Select lambda that only casts adds an unnecessary delegate invocation; Cast<T>() does it directly.

var strings = objects
.Select(o => (string)o)
.ToList();
var strings = objects
.Cast<string>()
.ToList();

Use Cast<T>() for type conversion.