http://stackoverflow.com/questions/22940317/protected-vs-protected-internal-again-in-c-sharp

protected means that you can access the member from any subtype (and of course from the declaring type itself). So regardless of where that subtype is, even if it is in another assembly, you will still have access to all protected members.

internal means that you can access the member from any type in the same assembly. So even a completely unrelated class that lives in the same assembly can access the member.

protected internal combines both, meaning that both apply separately. So you can access the member from any subtype, and you can also access the member from any type in the same assembly.

// Assembly 1
class A {
protected int foo;
internal int bar;
protected internal int baz;
} class B : A {} // can access: foo, bar, baz
class C {} // can access: bar, baz protected类型的foo无法被访问,所以protected internal访问范围比protected高 // Assembly 2
class D : A {} // can access: foo, baz internal类型的bar无法被访问,所以protected internal访问范围比internal高
class E {} // can access neither

在Assembly1内部

public class A
{
protected int foo;
internal int bar;
protected internal int baz;
} /// <summary>
/// can access: foo, bar, baz
/// </summary>
public class B : A
{
void Method()
{
A a = new A();
//a.foo = 1;
//can not access protected member 'A.foo' via a qualifier of type 'A'
//the qualifier must be of type of B(or derive from it)
a.bar = ;
a.baz = ; B b = new B();
b.foo = ;
b.bar = ;
b.baz = ;
}
} /// <summary>
/// can access: bar, baz
/// </summary>
class C
{
void Method()
{
A a = new A();
//a.foo = 1; A.foo is inaccessible due to its protectionlevel
a.bar = ;
a.baz = ; B b = new B();
//b.foo = 1; A.foo is inaccessible due to its protectionlevel
b.bar = ;
b.baz = ;
}
}

在Assembly2内部,AssemblyB将AssemblyA添加为引用

    /// <summary>
/// can access: foo, baz
/// </summary>
class D : A
{
void Method()
{
A a = new A();
//a.foo = 1;
//can not access protected member 'A.foo' via a qualifier of type 'A'
//the qualifier must be of type of B(or derive from it) //a.bar = 2; //A.bar is inaccessible due to its protection level //a.baz = 3;
//can not access protected member 'A.foo' via a qualifier of type 'A'
//the qualifier must be of type of B(or derive from it) B b = new B();
//b.foo = 1;
//can not access protected member 'A.foo' via a qualifier of type 'B'
//the qualifier must be of type of D(or derive from it) //b.bar = 2; //A.bar is inaccessible due to its protection level //b.baz = 3;
//can not access protected member 'A.foo' via a qualifier of type 'B'
//the qualifier must be of type of D(or derive from it) D d = new D();
d.foo = ;
//d.bar = 2; //A.bar is inaccessible due to its protection level
d.baz = ;
}
} /// <summary>
/// can access neither
/// </summary>
class E
{
void Method()
{
//什么都访问不到
}
}

What is the difference between 'protected' and 'protected internal'?

- Update answer 2019 -

You can find the difference in below table based accessibility is yes,

Protected vs protected internal (Again) in c#的更多相关文章

  1. c#中的访问修饰符Protected,privet ,public, internal,和internal protected

    Protected,privet ,public, internal,和internal protected的区别 Private修饰的,只能值类内部使用,外部不可以使用,子类不能直接访问,但可以通过 ...

  2. 简述private,protected,public,internal修饰符的访问权限

    private:私有成员,在类的内部才可以访问 protected:保护成员,在类的内部和继承类中可以访问 public:公共成员,完全公开,没有访问限制 internal:当前程序集内可以访问

  3. c# protected public private internal

    1 internal 只能在一个项目中引用,不能跨项目引用,只有在同一程序集的文件中 2 public 最高级别的访问权限 对访问公共成员没有限制 3 private 最低级别的访问权限 只能在声明它 ...

  4. 访问修饰符(public,private,protected,internal,sealed,abstract)

    为了控件C#中的对象的访问权限,定义对象时可以在前面添加修饰符. 修饰符有五种:private(私有的),protected(受保护的),internal(程序集内部的),public(公开的),以及 ...

  5. 深入浅出OOP(五): C#访问修饰符(Public/Private/Protected/Internal/Sealed/Constants)

    访问修饰符(或者叫访问控制符)是面向对象语言的特性之一,用于对类.类成员函数.类成员变量进行访问控制.同时,访问控制符也是语法保留关键字,用于封装组件. Public, Private, Protec ...

  6. 对访问修饰关键字public, protected, internal and private的说明

    对访问修饰关键字public, protected, internal and private的说明1.msdn: Internal types or members are accessible o ...

  7. protected internal修饰符

    见过这样的修饰符,但是没有仔细考虑过,今天做一个小练习. 先给出一个链接,别人在网上讨论的:http://wenku.baidu.com/view/4023f65abe23482fb4da4cfe.h ...

  8. C#中public、private、protected、internal、protected internal (转载)

    在C#语言中,共有五种访问修饰符:public.private.protected.internal.protected internal.作用范围如下表:访问修饰符 说明public 公有访问.不受 ...

  9. C#访问修饰符(public,private,protected,internal,sealed,abstract)

    为了控件C#中的对象的访问权限,定义对象时可以在前面添加修饰符. 修饰符有五种:private(私有的),protected(受保护的),internal(程序集内部的),public(公开的),以及 ...

随机推荐

  1. Android Measure 体系简单总结

    Android对View的测量是半协商半强制半模糊半具体的. 测量过程中的两套尺寸体系:  [半强制] ParentView**约束ChildView: **MeasureSpec(通过measure ...

  2. Vue核心知识-computed和watch的使用场景和方法

    https://www.jianshu.com/p/bb7a2244c7ca

  3. public private protected

    初学C++的朋友经常在类中看到public,protected,private以及它们在继承中表示的一些访问范围,很容易搞糊涂.今天本文就来十分分析一下C++中public.protected及pri ...

  4. CAD如何动态绘制带面积周长的圆?

    CAD绘制图像的过程中,画圆的情况是非常常见的,用户可以在控件视区点取任意一点做为圆心,再动态点取半径绘制圆. 主要用到函数说明: _DMxDrawX::DrawCircle 绘制一个圆.详细说明如下 ...

  5. win10 javac无效

    win10配置环境变量时,要写绝对路径,不再需要写JAVA_HOME和classpaht,直接在pass上添加全路径就可以了.

  6. 洛谷——P1516 青蛙的约会

    P1516 青蛙的约会 题目描述 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件 ...

  7. ROS lesson 1

    ROS ROS官网 ROS 简介 ROS 是 Robot Operation System 的简写,并且 他诞生在2000年后,至今有10余年了,运行在 Linux(Ubuntu) 上 ROS 不是 ...

  8. jsp页面应用简记

    1.记录总数据条数 <div class="" > <span class="">共有数据:<strong>${fn:len ...

  9. 08 Python基础数据结构

    目录: 1) 列表 2) 元组 3) 字符串 4) bytes 5) bytearray 6) 字典 7) 集合 8) 冻集合 """1. 列表特性2. 创建3. 增加4 ...

  10. 如何卸载 win10 自带的“电影和电视”软件

    参考这里: https://answers.microsoft.com/zh-hans/windows/forum/apps_windows_10-movies/win10%E7%9A%84%E7%9 ...