I have a very special case in which I need to call a protected method from outside a class. I am very conscious about what I do programmingwise, but I would not be entirely opposed to doing so in this one special case I have. In all other cases, I need to continue disallowing access to the internal method, and so I would like to keep the...
Why is it that when implementing an interface, if I make the method public I do not have to explicitly specify the interface, but if I make it private I have to...like such (GetQueryString is a method from IBar):
public class Foo : IBar
{
//This doesn't compile
string GetQueryString()
{
///...
}
//But this ...
Can a class be protected in.NET?
Why is / isn't this possible?
...
What are public, private and protected in object oriented programming?
...
In general, according to the OOP paradigm, my understanding of encapsulation basically says:
If a member is private, it can only be accessed by the class.
If a member is protected, it can only be accessed by the base class and any derived classes.
If a member is public, it can be accessed by anyone.
If I have a nested class, can I de...
I'd like to create an internal auto-property:
internal bool IP { get; protected internal set; }
I thought it would be possible to make the setter protected or protected internal - but I always get the error accessibility modifier must be more restrictive than the property. Isn't that the case? Private does not help me, here.
EDIT:
Th...
I am getting a compile error from the following property.
The error is:
"The modifier 'public' is not valid for this item"
public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties
{
get { return properties; }
set { properties = value; }
}
but if I remove the IWorkItemControl it compiles fine.
W...
I'm a student looking for resources which can help me further understand how to properly apply access modifiers to members/types as I code them.
I know (in C#) what restrictions access modifiers like private, public, protected, etc. put into place. When I code my own little projects I have a tendency to just make everything public. I'm ...
If I put a control in a .aspx file like this;
<asp:TextBox ID="protectedTextBox" runat="server">Some info</asp:TextBox>
I get a declared control in the page's .aspx.designer.cs file;
protected global::System.Web.UI.WebControls.TextBox protectedTextBox;
But I'd like to change the access modifier of the control to public. Is there an...
Hi All,
I understand that the rule of thumb in OOD is to minimize access to all members of a given object as best as can be reasonably accomplished.
C# and Java both seem to implement the same set of access modifiers; however, something which has bewildered me for some time now is why Java classes seem to be mostly declared as public w...
What is the equivalent of Java's final in C#?
EDIT: Sorry, I should have been clearer. I meant what is the equivalent when applied to a member variable - so it must be assigned once and only once.
...
What is the equivalent of Java's default (package) access in C#? Is there one? Is there anyway to restrict access to a particular namespace?
The Problem:
I'm trying to restrict access to certain methods to just my NUnit tests - in JUnit I would do this by making the methods package access and having the test in the same package but un...
which access modifiers which when used with the method makes it available to all the class and subclasses within a package??
...
I'd like to have multiple versions of an object with different access modifiers on the properties
For example I might have a user class-
public abstract class UserInfo
{
internal UserInfo()
{
}
public virtual int ID { get; set; }
public virtual string Password { internal get; set; }
public virtual string Usernam...
Hi i'm a really noob, but i learn programming and after structured programming with Pascal language, i'm beginning to learn about OOP with Delphi.
So, i don't really understand the difference between the 'strict private' instruction and the 'protected' one.. So here is my code, it's about a "bag" creation, it's just the introduction of ...
I've recently been trying to learn the Object-Oriented aspects of F#, and have become curious about how to restrict access to types/modules in the language.
More specifically, I want to know the difference between writing this:
Example.fsi
module Stack =
val foo : string
Example.fs
module Stack =
let foo = "foo"
let bar...
Hi, is it possible to get this stuff working(some way to force Objectfactory create instances like Activator)
in the below example everything is placed in a sigle assembly
public interface IUnitOfWorkFactory
{
IUnitOfWork Create();
}
internal class NHUnitOfWorkFactory : IUnitOfWorkFactory
{
public IUnitOfWork Create()
{
...
The responsibility of the visibility of a method is relegated to the class that implements the interface.
public interface IMyInterface
{
bool GetMyInfo(string request);
}
In C# set access modifier public, private or protected before the method GetMyInfo() generates the following error: The modifier 'private' is not valid for this i...
Very often when Visual Studio generates code (for example generating an event handler stub) it omits access modifiers for members. I would like it to stop doing this. Is there a setting for this?
...
Variables, methods and classes can receive various security levels.
From my C# experience, there is:
public
internal
protected
protected internal
private
Now, I understand the use of making methods and classes private, or internal or protected, but what about variables? Even if I make a variable private, I can use a Property to call it...