C # explicitly declares member interface

How to declare an explicit member of an interface? .Ie:

    public interface IPerfil
    {
        int IDPerfil
        {
            get;
            set;
        }
        int IDMarca
        {
            get;
            set;
        }
        int IDRegional
        {
            get;
            set;
        }
        int IDFilial
        {
            get;
            set;
        }
}

then

    public class ComentariosPerfil : BaseComentarios, IPerfil
    {
        public int IPerfil.IDFilial
        {
            get;
            set;
        }
[...]

I get a compilation error stating that the "public" modifier is not applicable to this element.

The question arises:

I want this property to be publicly available. I cannot write modifiers in the interface, for example:

   public int IDPerfil
        {
            get;
            set;
        }

So, how can I explicitly implement a member of an interface and make it public?

+3
source share
2 answers

For explicitly implemented interfaces, you cannot specify visibility. It is taken from visibility in the interface definition.

, . , IPerfil:

public class ComentariosPerfil : BaseComentarios, IPerfil 
{ 
    int IPerfil.IDFilial 
    { 
        get; 
        set; 
    }
+6

, . , , . , , .

0

Source: https://habr.com/ru/post/1770971/


All Articles