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. c# Dictionary 扩展方法

    主要用于接口请求,数据转换 #region Dictionary 扩展方法 public static string getString(this Dictionary<string, stri ...

  2. UVA - 10603 Fill(BFS求最小值问题)

    题目: 给出三个杯子(没有刻度线)的容量,起初之后第三个杯子是满的,其他的两个杯子是空的,容量分别是a.b.c.问最少需要倒多少升水才能让某一个杯子中的水有d升?如果不能恰好做到d升,就让某一个杯子里 ...

  3. FileOutputStream将从一个文件中读取的内容写到另一个文件中

    package com.janson.day2018082 import java.io.FileInputStream; import java.io.FileNotFoundException; ...

  4. 【eclipse】外部 jar 包导入教程

    JavaWeb 项目中,可以直接将要导入的 jar 程序包复制到你项目下的 WEB-INF/lib 文件夹下,将来程序移动到别的机子上测试时也能正常运行.如果是普通 Java 工程的话,我们可以在项目 ...

  5. Linux配置网卡、网卡会话、网卡bonding

    配置网卡  1.路径:  /etc/sysconfig/network-scripts/ifcfg-eno16777728 2.含义:HWADDR=00:0C:29:9C:D6:4D   Mac地址 ...

  6. svn汉化包安装无效的解决办法

    下载svn汉化包要和对应的svn客户端版本对应,否则安装无效, 在安装前要想将svn安装目录下的languages目录下的文件全部删除 还有一点要注意的是 汉化包安装要放在svn安装目录下进行安装,它 ...

  7. 关于图片预览使用base64在chrome上的性能问题解决方法

    在开发后台上传图片的功能时候使用base64预览图片,结果在传入大量图片后导致chrome崩溃,代码如下 var img = new Image(); var render = new FileRea ...

  8. python3中整数和小数的转换

    在整数除法中,除法(/)总是返回一个浮点数,如果只想得到整数的结果,丢弃可能的分数部分,可以使用运算符 // : >>> 17 / 3 # 整数除法返回浮点型 5.666666666 ...

  9. 正确的在循环list的时候删除list里面的元素

    s = [1,2,3,4,5] for i in s: s.remove(i) print(s)   输出结果:[2, 4] 1.当第一次删除后,后面的元素会前移,此时s=[2,3,4,5], 2.然 ...

  10. STM32单片机串口一键下载电路与操作方法详解

    STM32三种启动模式对应的存储介质均是芯片内置的,它们是:1)用户闪存 = 芯片内置的Flash.2)SRAM = 芯片内置的RAM区,就是内存啦.3)系统存储器 = 芯片内部一块特定的区域,芯片出 ...