Is deriving from HybridDictionary possible?

  • Thread starter Thread starter Paul Tomlinson
  • Start date Start date
P

Paul Tomlinson

All, I have a very simple class and all I want to do is override the add and
remove methods for logging, thats it.
This is my class, however the only methods which I can override are equals,
gethashcode and tostring.

Why can't I override add and remove?


using System;
using System.Collections.Specialized;
namespace myApp
{
/***************************************************************************/
// CustomHybridDictionary
/***************************************************************************/
public class CustomHybridDictionary : HybridDictionary
{
/***************************************************************************/
// default constructor
/***************************************************************************/
public CustomHybridDictionary()
{
}
}
}
 
Paul said:
All, I have a very simple class and all I want to do is override the add and
remove methods for logging, thats it.
This is my class, however the only methods which I can override are equals,
gethashcode and tostring.

Why can't I override add and remove?


using System;
using System.Collections.Specialized;
namespace myApp
{
/***************************************************************************/
// CustomHybridDictionary
/***************************************************************************/
public class CustomHybridDictionary : HybridDictionary
{
/***************************************************************************/
// default constructor
/***************************************************************************/
public CustomHybridDictionary()
{
}
}
}

The compiler message explains it goog enough.


error CS0506: 'QuickTest1.CustomHybridDictionary.Add(object, object)' :
cannot override inherited member
'System.Collections.Specialized.HybridDictionary.Add(object, object)'
because it is not marked virtual, abstract, or override

However, you can mark it "new", this will compile, just be sure this is
not "override" anymore, it means, when you create a base class and point
to the CustomHybridDictionary , it won't call the Add method in your class.

John.
 
Back
Top