I have this C# code:
abstract class MyList : IEnumerable<T> { public abstract IEnumerator<T> GetEnumerator(); //abstract IEnumerator IEnumerable.GetEnumerator(); }
As is, I get:
'Type' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'.
remove the comment and I get:
The modifier 'abstract' is not valid for this item
How do I make an explicit implementation abstract
An explicit interface implementation is a class member that is only called through the specified interface. Name the class member by prefixing it with the name of the interface and a period. For example: C# Copy.
Resolving conflicts here ..... "Implicit Implementation" - means just simple implementation of a particular method having same name and same signature which belongs to the same class itself, where as "Explicit Implementation" - means implementation of a method using their Interface name having same name and signature ...
An Interface is a collection of loosely bound items that have a common functionality or attributes. Interfaces contain method signatures, properties, events etc. Interfaces are used so that one class or struct can implement multiple behaviors.
Abstract class can contain methods, fields, constants, etc. Interface can only contains methods, properties, indexers, events. It can be fully, partially or not implemented. It should be fully implemented.
Interesting - I'm not sure you can. However, if this is your real code, do you ever want to implement the non-generic GetEnumerator()
in any way other than by calling the generic one?
I'd do this:
abstract class MyList<T> : IEnumerable<T> { public abstract IEnumerator<T> GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } }
That saves you from the tedium of having to implement it in every derived class - which would no doubt all use the same implementation.
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