csharpstandard icon indicating copy to clipboard operation
csharpstandard copied to clipboard

Example for explicit interface member implemenation

Open logeshkumars0604 opened this issue 1 year ago • 1 comments

Type of issue

Other (describe below)

Description

From: Explicit interface member implementations

interface IList<T>
{
    T[] GetElements();
}

interface IDictionary<K, V>
{
    V this[K key] { get; }
    void Add(K key, V value);
}

class List<T> : IList<T>, IDictionary<int, T>
{
    T[] IList<T>. GetElements() {...}
    T IDictionary<int, T>.this[int index] {...}
    void IDictionary<int, T>.Add(int index, T value) {...}
}

Here IDictionary<int,T>.this and IDictionary<int,T>.Add are explicit interface member implementations.


Question: Is IList<T>. GetElements() in T[] IList<T>. GetElements() {...} not an explicit interface member implementation?

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/interfaces

Content source URL

https://github.com/dotnet/csharpstandard/blob/draft-v8/standard/interfaces.md

logeshkumars0604 avatar Apr 26 '24 06:04 logeshkumars0604

Certainly looks that way to me. We'll discuss this in our next meeting in case I've missed something.

jskeet avatar Apr 26 '24 06:04 jskeet

Proposed fix: change GetElements to be implicit:

public T[] GetElements() {...}

jskeet avatar May 15 '24 20:05 jskeet

Agreed in the meeting - I'll create a PR tomorrow.

jskeet avatar May 15 '24 20:05 jskeet