tagged [access-modifiers]

Partial classes and access modifier issue

Partial classes and access modifier issue According to [MSDN Documentation](http://msdn.microsoft.com/en-us/library/wa80x488.aspx) for partial classes : > All the parts must have the same accessibilit...

Static Class vs Protected Constructor

Static Class vs Protected Constructor I Am getting a warning message in my class, like [](https://i.stack.imgur.com/uXCBm.jpg) > `Protected``static` ## Solution The error is gone after I tried both th...

What is the difference between Dim, Global, Public, and Private as Modular Field Access Modifiers?

What is the difference between Dim, Global, Public, and Private as Modular Field Access Modifiers? In VB6/VBA, you can declare module-level variables outside of a specific `Sub` or `Function` method. ...

28 Sep at 17:52

Why can't we change access modifier while overriding methods in C#?

Why can't we change access modifier while overriding methods in C#? In C#, we can not change access modifier while overriding a method from base class. e.g. This is not valid in C#, It will give compi...

1 Aug at 16:57

internal abstract methods. Why would anyone have them?

internal abstract methods. Why would anyone have them? I was doing some code review today and came across an old code written by some developer. It goes something like this If you have a derived class...

Have you ever seen design with reasonable usage of protected internal access modifier?

Have you ever seen design with reasonable usage of protected internal access modifier? I haven't, but I don't say there isn't one. All of the C# developers who read this probably do know what is prote...

6 Oct at 20:4

Calling a private base method from a derived class in C#

Calling a private base method from a derived class in C# I have a base class, in which I wrote a private method to register some values. I did this to allow subclasses to register different stuff. The...

7 Aug at 00:56

Internal abstract class: how to hide usage outside assembly?

Internal abstract class: how to hide usage outside assembly? I have a common assembly/project that has an abstract base class, then several derived classes that I want to make public to other assembli...

How to change the access modifier of a user control

How to change the access modifier of a user control I have a user control created in xaml, lets name it "View". In the View.xaml.cs I changed the access modifier for the class View to internal: After ...

Public and Internal members in an Internal class?

Public and Internal members in an Internal class? Ok, so this may be a bit of a silly question, and there's certainly the obvious answer, but I was curious if I've missed any subtleties here. Is there...

How to make a property protected AND internal in C#?

How to make a property protected AND internal in C#? Here is my shortened abstract class: Here is a derived class: ``` class OnlineStatusReport : Report { static string[] headers = new string[] { ...

18 Jul at 10:16

Are there any reasons to use private properties in C#?

Are there any reasons to use private properties in C#? I just realized that the C# can also be used with a access modifier: Although this is technically interesting, I can't imagine when I would use i...

22 Jul at 15:41

Why is it not "inconsistent accessibility" to use a private nested type inside a generic type in the interface list?

Why is it not "inconsistent accessibility" to use a private nested type inside a generic type in the interface list? In case the title is not completely self-explanatory, here's the code that puzzles ...

Any reason to write the "private" keyword in C#?

Any reason to write the "private" keyword in C#? As far as I know, `private` is the default in C# (meaning that if I don't write `public`, `protected`, `internal`, etc. it will be `private` by default...

Error 1 Inconsistent accessibility: return type is less accessible than method

Error 1 Inconsistent accessibility: return type is less accessible than method When I'm building, VS show error. This is my code: ``` public Composite buildComposite(ComboBox subs, ComboBox bas) { i...

4 Jun at 15:10

.NET - how to make a class such that only one other specific class can instantiate it?

.NET - how to make a class such that only one other specific class can instantiate it? I'd like to have the following setup: ``` class Descriptor { public string Name { get; private set; } public ...

18 Dec at 16:9

Why have class-level access modifiers instead of object-level?

Why have class-level access modifiers instead of object-level? While using C#, I recently realised that I can call a `Foo` object's private functions from `Foo`'s static functions, and even from other...

3 May at 08:40

Prevent visual studio from limiting the setter method to internal

Prevent visual studio from limiting the setter method to internal Well, I use visual studio 2015 CE, update 2. One productivity hack I usually do is that I create empty model classes like: and then us...

C# private, static, and readonly

C# private, static, and readonly I was reviewing some code for log4net and I came across this. I am wondering why would you need to have private static readonly. From my understanding private would me...

9 Jun at 06:22

Why can't I access C# protected members except like this?

Why can't I access C# protected members except like this? This code: Generates this error: > Cannot access protected member 'C.F(D)' via a qualifier of type 'C'; the qualifier must be of type 'D' (or ...

What is the meaning of the planned "private protected" C# access modifier?

What is the meaning of the planned "private protected" C# access modifier? As part of the [Roslyn](https://github.com/dotnet/roslyn) documentation on GitHub, there's a page called [Language feature im...

18 Dec at 12:17

Why a function with protected modifier can be overridden and accessible every where?

Why a function with protected modifier can be overridden and accessible every where? I'm C# programmer new to D language. I'm a bit to confused with OOP in D programming language. Assuming that I have...

5 May at 01:53

Why is Unity ignoring the initialized value of a non-static public field?

Why is Unity ignoring the initialized value of a non-static public field? I'm using [InvokeRepeating()](http://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html) to call a method in ...

Testing properties with private setters

Testing properties with private setters Currently in a part of my project a domain object like below exists: ``` public class Address { public virtual string HouseName { get; set; } public virtual...

What is the use case for the (C# 7.2) "private protected" modifier?

What is the use case for the (C# 7.2) "private protected" modifier? [C# 7.2 introduces the private protected modifier](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/priva...

22 Nov at 14:21