Implementing a generic interface that inherits from a non-generic interface

I know how to implement a common interface that inherits a form not common, but there is something I don’t understand in this process:

Why shouldn't a universal interface method be declared public in a class that implements interfaces ?.

Example:

    interface InputTestSocket
    {
        object GetValue();
    }

    interface InputTestSocket<T> : InputTestSocket
    {
        new T GetValue();
    }

    class FloatInputSocketValues : InputTestSocket<float>
    {
        IFloatConvertable _output;
        public void SetConvertable(IFloatConvertable output) { _output = output; }

        //If I make this method public it won't compile. Musn't all interfaces be public?
        object InputTestSocket.GetValue() { return null; }

        public float GetValue() { return _output.ToFloat(); }
    }
+4
source share
1 answer

This is called an explicit interface implementation. You do this when you will not (or cannot) expose members to instance members of a particular type, but only make them available through the interface.

The reason the compiler complains about this:

CS0111 The type 'FloatInputSocketValues' already defines a member called GetValue with the same parameters

, , , :

//If I make this method public it won't compile. Musn't all interfaces be public?
public object GetValue() { return null; }

public float GetValue() { return _output.ToFloat(); }

.

, .

, , , , , :

something.GetValue()

, . , , , , , .

, :

interface ITest
{
    object GetValue();
}

public class Test : ITest
{
    public object GetValue() { return null; }

    // just a public method on our class
    public float GetValue() { return 0.0f; }
}
+3

All Articles