内部方法和数据结构.

leo*_*ora 3 c# scope internal

如果我有一个受保护的方法,我可以传入一个参数,其中数据类型被声明为内部?

Mar*_*ell 6

不,除非类型(受保护成员)本身是内部的.内部类型不能成为公共/受保护API的一部分,因为消费者无法使用它.

但是,您可以考虑使用公共接口来抽象类型 - 即

public interface IFoo {}
internal class Foo : IFoo {}
public class Bar {
    protected void Test(IFoo foo) {}
}
Run Code Online (Sandbox Code Playgroud)

泛型对此也很有用:

protected void Test<T>(T foo) where T : IFoo { }
Run Code Online (Sandbox Code Playgroud)