0

I have an internal class

namespace commonNamespace
{
    internal class A{}
}

i have another public class within the same assembly

public class B{}

I want to declare an array of type A in classB. ex:

namespace commonNamespace
{
    public class B
    {
        A[] array;
    }
}

I am getting inconsistent accessibility Level error message.Please let me know how can i do this.

3
  • 3
    Since A[] array is private (due to lack of an access modifier), I don't see why this is a problem. Is this field actually public? Commented Jul 19, 2012 at 13:52
  • 1
    What you have here should be fine. It's only an issue if array is declared public or protected. Commented Jul 19, 2012 at 13:53
  • The code you have posted compiles without issue. Commented Jul 20, 2012 at 5:43

2 Answers 2

2

You must have a public/protected field or property in B exposing some instance(s) of type A. Mark that as internal and you should be good to go.

Sign up to request clarification or add additional context in comments.

Comments

1

Just add access modifier to the field Array:

public class B
{
   internal A[] array;
}

This is the Access Modifiers hierarchy:

 public > protected > internal > internal protected > private

So just choose anything below protected and you will be fine.

3 Comments

That shouldn't help - as the default is to be private. So by declaring the array variable internal, you're actually increasing its visibility.
The access modifiers hierarchy is wrong, internal protected means internal or protected. So it can be accessed internally by any class, or only accessed by derived classes in other assemblies.
sorry i have the array object inside an interface which is public because i want to only expose the interface outside the assembly.But the class should not be exposed outside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.