Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# explicit declare member interface

How to declare explicit a member of a interface?.i.e:

    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 an compilation error,saying that "public" modifier cannot be applied to this item.

The question is:

I want this property to be public. I can't write modifiers in interface like:

   public int IDPerfil
        {
            get;
            set;
        }

So,how can I explicitly implement an interface member, and make it Public?

like image 830
ozsenegal Avatar asked Dec 29 '25 11:12

ozsenegal


1 Answers

For explicitly implemented interfaces you can't specify the visibility. It is taken from the visibility in the interface's definition.

So in your case use the following. The function will be public because that's the way the IPerfil interface is defined:

public class ComentariosPerfil : BaseComentarios, IPerfil 
{ 
    int IPerfil.IDFilial 
    { 
        get; 
        set; 
    }
like image 196
Russell McClure Avatar answered Jan 01 '26 02:01

Russell McClure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!