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. Protected Interface Members

Protected Interface Members

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 5 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.
  • A Offline
    A Offline
    Ambika Jadhav
    wrote on last edited by
    #1

    public interface IMyInterface
    {

    string myInterfaceProp{ get; }

    }

    public class MyClass :IMyInterface
    {
    public string myInterfaceProp
    {
    get { return "some value"; }
    }

    }

    public class UserClass
    {
    MyClass objMyClass =new MyClass ();
    objMyClass.
    }

    How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .

    L A B M 4 Replies Last reply
    0
    • A Ambika Jadhav

      public interface IMyInterface
      {

      string myInterfaceProp{ get; }

      }

      public class MyClass :IMyInterface
      {
      public string myInterfaceProp
      {
      get { return "some value"; }
      }

      }

      public class UserClass
      {
      MyClass objMyClass =new MyClass ();
      objMyClass.
      }

      How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Your question is not clear, what exactly are you trying to achieve here? If you make it private or protected then it will be inaccessible.

      One of these days I'm going to think of a really clever signature.

      1 Reply Last reply
      0
      • A Ambika Jadhav

        public interface IMyInterface
        {

        string myInterfaceProp{ get; }

        }

        public class MyClass :IMyInterface
        {
        public string myInterfaceProp
        {
        get { return "some value"; }
        }

        }

        public class UserClass
        {
        MyClass objMyClass =new MyClass ();
        objMyClass.
        }

        How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        You cant hide an interface method. An interface method has no implementation so you need not worry about hiding it.

        WP7.5 Apps - XKCD | Calvin | SMBC | Sound Meter | Speed Dial

        1 Reply Last reply
        0
        • A Ambika Jadhav

          public interface IMyInterface
          {

          string myInterfaceProp{ get; }

          }

          public class MyClass :IMyInterface
          {
          public string myInterfaceProp
          {
          get { return "some value"; }
          }

          }

          public class UserClass
          {
          MyClass objMyClass =new MyClass ();
          objMyClass.
          }

          How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          The whole point of an interface is that it defines, well, an interface: a public contract for your class, or for third party classes, and the methods and properties that it will expose. It doesn't define any content, it simply states 'if a class says it implements me, you must be able to do these operations on it'. Therefore it doesn't make sense to put protected methods or properties on an interface. If you don't want a property to be visible to the outside world, then don't add it to the interface!

          1 Reply Last reply
          0
          • A Ambika Jadhav

            public interface IMyInterface
            {

            string myInterfaceProp{ get; }

            }

            public class MyClass :IMyInterface
            {
            public string myInterfaceProp
            {
            get { return "some value"; }
            }

            }

            public class UserClass
            {
            MyClass objMyClass =new MyClass ();
            objMyClass.
            }

            How to hide the myInterfaceProp in the userclass when the "MyClass " instance is accessed? .

            M Offline
            M Offline
            markovl
            wrote on last edited by
            #5

            Your question is a bit vague, but I'll have a go. If you mean that you don't want to list myInterfaceProp as a member of the MyClass class (i.e. in Intellisense), implement the interface explicitly (What you're doing in your snippet is called implicit interface implementation). Try this:

            public class MyClass : IMyInterface
            {
            // Explicit IMyInterface implementation
            string IMyInterface.myInterfaceProp
            {
            get { return "some value"; }
            }
            }

            That way you want have access to this member if you try to access it directly from MyClass, but you'll need a cast to IMyInterface.

            2A

            A 1 Reply Last reply
            0
            • M markovl

              Your question is a bit vague, but I'll have a go. If you mean that you don't want to list myInterfaceProp as a member of the MyClass class (i.e. in Intellisense), implement the interface explicitly (What you're doing in your snippet is called implicit interface implementation). Try this:

              public class MyClass : IMyInterface
              {
              // Explicit IMyInterface implementation
              string IMyInterface.myInterfaceProp
              {
              get { return "some value"; }
              }
              }

              That way you want have access to this member if you try to access it directly from MyClass, but you'll need a cast to IMyInterface.

              2A

              A Offline
              A Offline
              Ambika Jadhav
              wrote on last edited by
              #6

              Explicit interface implemntation solved my problem. Thank u so much for the suggestion.

              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