Question

if i have a protected method, can i pass in a parameter where the data type is declared internal?

Was it helpful?

Solution

No, unless the type (with the protected member) is itself internal. Internal types cannot be part of a public/protected API, as the consumer would have no way of using it.

You could, however, consider using a public interface to abstract the type - i.e.

public interface IFoo {}
internal class Foo : IFoo {}
public class Bar {
    protected void Test(IFoo foo) {}
}

Generics can be useful for this too:

protected void Test<T>(T foo) where T : IFoo { }

OTHER TIPS

Not if the class that contains the protected method is externally visible. That's because some external class could derive from that class and would need to know the type of the parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top