System.Collections.DictionaryBase.GetEnumerator cannot be overload

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I've tried to write an method overriding
System.Collections.DictionaryBase.GetEnumerator(), but my C# compiler (VS
..NET 2003) outputed 'error CS0506'. This means
System.Collections.DictionaryBase.GetEnumerator() is not virtual one, but in
the .NET class library reference, it is described as 'public virtual
IDictionaryEnumerator GetEnumerator();'. Also, the object browser in VS.NET
2003 says DictionaryBase.GetEnumrator() is 'public virtual new
System.Collections.IDictionaryEnumerator GetEnumerator ( )'.

Is this a bug of the compiler or the document? Or Is there something wrong
in my understandings?
 
Hi

I agree with Mattias's suggestion.
Here is the MSIL code copied from ildasm.

..method public hidebysig newslot virtual final
instance class System.Collections.IDictionaryEnumerator
GetEnumerator() cil managed
{
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance class System.Collections.Hashtable
System.Collections.DictionaryBase::get_InnerHashtable()
IL_0006: callvirt instance class
System.Collections.IDictionaryEnumerator
System.Collections.Hashtable::GetEnumerator()
IL_000b: ret
} // end of method DictionaryBase::GetEnumerator

We will find that the method is marked as virtual final, the final will
prevent it from being overrided.

For detailed information, you may take a look at the book below.
Essential .NET Volumn 1: The Common Language Runtime written by Don Box,
Chris Sells.

Chapter 6 Methods

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you for the answer.

Mattias Sjögren said:
The method is virtual but sealed.

I wrote a tiny program at once and made sure that IsFinal property of
MethodInfo of the method is certainly true.
The bottom line is that the document hasn't described its definition enough,
isn't it?
 
Thank you for the answer.
I'm not so familiar with MSIL codes as I can understand it thoroghly, but I
appreciate what you've done for me.
 
Hi

Thanks for your feedback.
You are welcome.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top