Inconsistent availability for class definition

I am adding some related CLR properties to the current WPF application in my App class, and I cannot compile due to this inconsistent availability error.

Inconsistent availability: the property type "SomeProj.Error" is less accessible than the property "SomeProj.App.LatestError"

To fix this error, I had to change class Error to public class Error .

In VB, classes were considered public and most of the time passed this access modifier. Isn't that true in C #?

I just recently made a vb-> C # jump and small nuances like this in the syntax slow me down.

+4
source share
3 answers

Although it is generally believed that good practice is explicit in all access modifiers, it is not unreasonable to allow them to be omitted with some default.

Of course, this default should be reasonable. If the default value was publicly available and used improperly, there would be no way to statically determine that it was an error (unless it disclosed a type that was defined elsewhere with less access), the code could go for several months or years before someone noticed an error, and then fixing it would be a violation of changes to the assembly.

Since the default value is private, where applicable, and internal in all other cases, if it is an error, this will lead to a compiler error (as something requires it to have more access), which was caught easily or in the class just not visible to other builds (easily caught, especially with most IDEs).

Limiting defaults is the obvious way.

0
source

Things declared outside of a class or structure will be internal by default. Things declared inside a class or structure will be private by default. contact http://msdn.microsoft.com/en-us/library/ba0a1yw2(VS.80).aspx

+4
source

I don’t know about vb, but in C # classes, by default, there are restrictive modifiers , which means they are internal if they are not nested in another class - in this case they are private .

Here's the complete guide (-:

+4
source

All Articles