Protected Interface Members
-
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? .
-
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? .
-
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? .
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
-
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? .
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!
-
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? .
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 theMyClass
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 toIMyInterface
.2A
-
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 theMyClass
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 toIMyInterface
.2A
Explicit interface implemntation solved my problem. Thank u so much for the suggestion.