Tuesday, July 15, 2008

Private & Public behaviours with Explicit interface member implementations


Have a look at the below code :

InterfaceCode

Here we are using the Explicit interface member implementation to differentiate the methods.

Now if we try to access these methods from an instance variable. . .

privateIntellense

We can’t !!! Because there is no access modifier specified in the implementation and hence the methods are treated as ‘private’.

So we try specifying the ‘public’ access modifier for these methods but that too generates a compiler error in visual studio !!!

So then how do we actually use any of those methods . . . .

privateIntellenseDone

So what’s confusing here is that although the methods were private they are behaving like public.

ilcode

Finally I managed to find the answer to this behaviour. . . .

Here is a good explanation of this and how the IL code for implicit & explicit Interface Contracts.

No comments:

AddIn