What is the purpose of new() while declaration of BaseEntityCollection class?
If I'm going to remove it, I got an error with the following message "T must be a non-abstract type with a public parameterless constructor in order to use it as parameter ..."
public abstract partial class BaseEntityCollection<T> :
List<T> where T : BaseEntity, new()
Writing new()
forces the parameter to have a default constructor.
Without it, you can't write new T()
.
Your error happens when you try to pass a non-new()
type as a new()
'd parameter.
Also, do not inherit List<T>
.
Instead, you should inherit Collection<T>
, which is designed for inheritance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With