C#: Inheritance Problem with List

前端 未结 4 1880
面向向阳花
面向向阳花 2020-12-19 10:55

Let\'s assume this class in C#:

public class LimitedList : List
{
    private int _maxitems = 500;

    public void Add(T value) /* Adding          


        
4条回答
  •  醉话见心
    2020-12-19 11:33

    Like others have stated, you need to add the new keyword. The reason for this is because in the base class (List) the Add method hasn't been marked with the keyword "virtual" which basically means "overridable". Therefore, it should be marked as "new".

提交回复
热议问题