Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

12 August 2012

Can we assign access modifiers to Inteface method singnatures


In this tip we will see, can we assign access modifiers(Public/Private/Protected/internal/Protected Internal))  to Interface method signatures.



    public /internal interface Itest
    {
        protected int ProtectedMethod(); //Compile Error
        internal int internalMethod();//Compile Error
        private int privateMethod();//Compile Error
        protected internal int ProtectedInternalMethod();//Compile Error
        public int publicMethod();//Compile Error

    }

when we try to add any of access modifiers to interface methods we will get compile time error as "The modifier 'public/protected/private/internal ' is not valid for this item". Even we can not assign a public modifier to methods.

But we can add Public/internal modifiers for an interface name.

0 Comments:

Post a Comment