protected (C# Reference)
https://msdn.microsoft.com/en-us/library/bcd5672a.aspx
The protected keyword is a member access modifier.
A protected member is accessible within its class and by derived class instances.
For a comparison of protected with the other access modifiers, see Accessibility Levels.
Example
A protected member of a base class is accessible in a derived class only if the access occurs through the derived class type.
For example, consider the following code segment:
class A
{
protected int x = ;
} class B : A
{
static void Main()
{
A a = new A();
B b = new B(); // Error CS1540, because x can only be accessed by
// classes derived from A.
// a.x = 10; // OK, because this class derives from A.
b.x = ;
}
}
The statement a.x = 10 generates an error because it is made within the static method Main, and not an instance of class B.
Struct members cannot be protected because the struct cannot be inherited.
Example
In this example, the class DerivedPoint is derived from Point.
Therefore, you can access the protected members of the base class directly from the derived class.
class Point
{
protected int x;
protected int y;
} class DerivedPoint: Point
{
static void Main()
{
DerivedPoint dpoint = new DerivedPoint(); // Direct access to protected members:
dpoint.x = ;
dpoint.y = ;
Console.WriteLine("x = {0}, y = {1}", dpoint.x, dpoint.y);
}
}
// Output: x = 10, y = 15
If you change the access levels of x and y to private, the compiler will issue the error messages:
'Point.y' is inaccessible due to its protection level.
'Point.x' is inaccessible due to its protection level.
C# Language Specification
For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.
See Also
C# Reference
C# Programming Guide
C# Keywords
Access Modifiers (C# Reference)
Accessibility Levels (C# Reference)
Modifiers (C# Reference)
public (C# Reference)
private (C# Reference)
internal (C# Reference)
protected (C# Reference)的更多相关文章
- 设计模式之美:Command(命令)
索引 别名 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):直接注入 Receiver 对象,Command 决定调用哪个方法. 实现方式(二):注入 Receiver 的指定方法, ...
- 【Java&Android开源库代码剖析】のAndroid-Universal-Image-Loader-part1
做Android app开发的同学应该都听说过或者用过nostra13的Android-Universal-Image-Loader开源库,它在图片异步加载.缓存和显示等方面提供了强大灵活的框架.之前 ...
- android universal image loader 缓冲原理详解
1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL ...
- Android -- ImageLoader简析
图片的内存缓存实现 Image-Loader库有一个较完整的内存缓存实现,使用者可以根据需要选择已经实现的策略,也可以定制自己项目中需要的策略. 内存缓存实现代码在memory和memory.impl ...
- Java中的软(弱)引用
一.Java中的强.软.弱.虚引用 在JDK中我们能够看到有一个java.lang.ref的包.这个包中就是Java中实现强.软.弱.虚引用的包,例如以下: PhantomReference 虚引用: ...
- 从设计到实现,一步步教你实现Android-Universal-ImageLoader-缓存
转载请标明出处,本文出自:chaossss的博客 Android-Universal-ImageLoader Github 地址 Cache 我们要对图片进行缓存.有两种方式:内存缓存和本地缓存. 这 ...
- Android-Universal-Image-Loader学习笔记(3)--内存缓存
前面的两篇博客写了文件缓存.如今说说Android-Universal-Image-Loader的内存缓存.该内存缓存涉及到的类如图所看到的 这些类的继承关系例如以下图所看到的: 如同文件缓存一样,内 ...
- 深入解析开源项目之Universal-Image-Loader(二)内存---缓存篇
珍惜作者劳动成果,如需转载,请注明出处. http://blog.csdn.net/zhengzechuan91/article/details/50292871 Universal-Image-Lo ...
- 网络拓扑实例之RRPP单环(五)
组网图形 RRPP简介 在城域网和企业网的网络规划以及实际组网应用中大多会采用环网结构来提高网络的可靠性.采用环网结构的好处是:当环上任意一个节点或节点之间的链路发生故障,都可以将数据流量切换到备份链 ...
随机推荐
- 02Oracle Database 安装,卸载,系统服务,系统组件及系统表空间
Oracle Database 安装,卸载,系统服务,系统组件及系统表空间 Oracle Database 安装 Oracle Database 卸载 Oracle Database 系统服务 Ora ...
- Oracle XE WM_CONCAT undifine
用docker 跑了个oracle XE 报错 没有WM_CONCAT 下载三个sql文件然后按顺序执行后可以正常使用 一:下载三个文件 解压到 oracle 目录下面 (要能找到,注意权限要o ...
- 这段代码很Pythonic | 相见恨晚的 itertools 库
前言 最近事情不是很多,想写一些技术文章分享给大家,同时也对自己一段时间来碎片化接受的知识进行一下梳理,所谓写清楚才能说清楚,说清楚才能想清楚,就是这个道理了. 很多人都致力于把Python代码写得更 ...
- Django - 自定义simple_tag
使用现有函数: 通过对传入的参数,后面跟一个管道符号+python函数,来完成对传入参数的修改. 返回值 自定义simple_tag: 具体操作步骤如下: 1.在某个app下,创建目录template ...
- 数字图像处理技术在TWaver可视化中的应用
数字图像处理(Digital Image Processing)又称为计算机图像处理,它是指将图像信号转换成数字信号并利用计算机对其进行处理的过程.常用的图像处理方法有图像增强.复原.编码.压缩等,数 ...
- manacher(马拉车)算法
断断续续地看了两天的马拉车算法,可算是给搞明白了(贼开心),这算是自己搞懂的第一个算法了(23333333333333)这个算法照目前自己的理解来看,貌似就只能求个字符串中的回文串(接触这个算法是要求 ...
- LINUX应用开发工程师职位(含答案)
就业模拟测试题-LINUX应用开发工程师职位 本试卷从考试酷examcoo网站导出,文件格式为mht,请用WORD/WPS打开,并另存为doc/docx格式后再使用 试卷编号:143989试卷录入者: ...
- Keil uVision “已停止工作”
之前一直受这个问题的困扰,但是因为只是下载程序,下载镜像文件完事就算了.随便keil挂掉. 今天要调试程序,发现开启调试keil就挂掉了,烦. 解决办法参见: http://218.244.144.1 ...
- JRobin绘制指定时间段的流量图
http://www.micmiu.com/enterprise-app/snmp/jrobin-graph-rpn/
- bzoj——2982: combination
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 611 Solved: 368[Submit][Status][Di ...