Ir al contenido

Use collection abstraction (ARCH705)

Esta página aún no está disponible en tu idioma.

Key dotnet.codequality.use-collection-abstraction · Severity info · Category codequality · Principle DependencyInversion

Returning concrete types like List<T> from public APIs leaks the internal data structure and couples callers to a specific implementation. Prefer abstractions such as IReadOnlyList<T>.

public List<Customer> GetCustomers()
{
return _customers;
}
public IReadOnlyList<Customer> GetCustomers()
{
return _customers;
}

Change return and parameter types to suitable abstractions like IEnumerable<T>, IReadOnlyList<T>, or IReadOnlyCollection<T>.