Reputation: 31625
I'm trying to do something and I came across an error that I cannot understand why.
public static class XYZ
{
private class Foo : SomethingIWantToInheritFrom
{
public Foo()
{
}
}
public static Foo Bar = new Foo();
}
This is giving me the following error related to the Bar
property:
Inconsistent accessibility: field type 'XYZ.Foo' is less accessible than field 'XYZ.Bar'
Why does this error happen?
Am I not allowed to create a static property that has the same type of a class inside my static class?
Edit: Bar
needs to be public so I can access it like Foo.Bar
. What I don't want is for other code to have access to the Foo
class.
Upvotes: 0
Views: 113
Reputation: 10874
What you're trying to do makes no sense. You want your callers to be able to call XYZ.Bar
, but they don't get to know the type of the object they get back.
You could change the type of the Bar property to SomethingIWantToInheritFrom
, if that is a public type.
Upvotes: 5