How to Implement Private methods in an Interface
-
pls i want to implement a private method on an interface, and i get the Error: Class cannot implement an interface member because it is not public. I am creating a COM Object in c# and the mthods of my calss must be protected. Pls is there another way of doing this. Thanks.
-
pls i want to implement a private method on an interface, and i get the Error: Class cannot implement an interface member because it is not public. I am creating a COM Object in c# and the mthods of my calss must be protected. Pls is there another way of doing this. Thanks.
You can't. If you think about it, it makes sense. The method wouldn't be accessible to consumers of the interface so it would be pointless.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
pls i want to implement a private method on an interface, and i get the Error: Class cannot implement an interface member because it is not public. I am creating a COM Object in c# and the mthods of my calss must be protected. Pls is there another way of doing this. Thanks.
You can't it is against the language syntax because, as DaveyM_nn_ said, it wouldn't make sense. Interfaces are there to define members that are publically available in the class. If you want to protect code from external use it cannot be part of the Interface. You can however call private or protected methods (which cannot be in the Interface) from your public ones (which can).
-
pls i want to implement a private method on an interface, and i get the Error: Class cannot implement an interface member because it is not public. I am creating a COM Object in c# and the mthods of my calss must be protected. Pls is there another way of doing this. Thanks.
Perhaps you should sit back and reflect on the word "interface".
-
Perhaps you should sit back and reflect on the word "interface".
it shares 5 letters with private, and only 2 with public. :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
it shares 5 letters with private, and only 2 with public. :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
And yet is shares 6 with in-your-face.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
pls i want to implement a private method on an interface, and i get the Error: Class cannot implement an interface member because it is not public. I am creating a COM Object in c# and the mthods of my calss must be protected. Pls is there another way of doing this. Thanks.
What about an abstract base class instead of an interface? There you can use something like
protected abstract void MyMethod();
-
And yet is shares 6 with in-your-face.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
I'd say 7, but you're trying to change the subject here. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Perhaps you should sit back and reflect on the word "interface".
PIEBALDconsult wrote:
reflect on the word "interface".
ecafretni? I doubt that'll help him much :-)
-
PIEBALDconsult wrote:
reflect on the word "interface".
ecafretni? I doubt that'll help him much :-)
That's ancient Sumatran - it means only public methods. It comes from a time when sacrifices were common place and there was a need to appease the gods by performing the sacrifice in public. They tried it in private for a while, but the populace started to suspect that all the pigs they were bringing to be sacrificed were just ending up as a really great luau.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads