Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Implement Private methods in an Interface

How to Implement Private methods in an Interface

Scheduled Pinned Locked Moved C#
csharpcomhelptutorial
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Enobong Adahada
    wrote on last edited by
    #1

    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.

    D K P B 4 Replies Last reply
    0
    • E Enobong Adahada

      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.

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • E Enobong Adahada

        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.

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        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).

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]

        1 Reply Last reply
        0
        • E Enobong Adahada

          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.

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          Perhaps you should sit back and reflect on the word "interface".

          L K 2 Replies Last reply
          0
          • P PIEBALDconsult

            Perhaps you should sit back and reflect on the word "interface".

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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.

            P 1 Reply Last reply
            0
            • L Luc Pattyn

              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.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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

              My blog | My articles | MoXAML PowerToys | Onyx

              L 1 Reply Last reply
              0
              • E Enobong Adahada

                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.

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                What about an abstract base class instead of an interface? There you can use something like protected abstract void MyMethod();

                1 Reply Last reply
                0
                • P Pete OHanlon

                  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

                  My blog | My articles | MoXAML PowerToys | Onyx

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Perhaps you should sit back and reflect on the word "interface".

                    K Offline
                    K Offline
                    Keith Barrow
                    wrote on last edited by
                    #9

                    PIEBALDconsult wrote:

                    reflect on the word "interface".

                    ecafretni? I doubt that'll help him much :-)

                    Sort of a cross between Lawrence of Arabia and Dilbert.[^]

                    P 1 Reply Last reply
                    0
                    • K Keith Barrow

                      PIEBALDconsult wrote:

                      reflect on the word "interface".

                      ecafretni? I doubt that'll help him much :-)

                      Sort of a cross between Lawrence of Arabia and Dilbert.[^]

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      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

                      My blog | My articles | MoXAML PowerToys | Onyx

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups