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简介 在城域网和企业网的网络规划以及实际组网应用中大多会采用环网结构来提高网络的可靠性.采用环网结构的好处是:当环上任意一个节点或节点之间的链路发生故障,都可以将数据流量切换到备份链 ...
随机推荐
- 浅谈FFC
FFC(Flexible Formatting Context) CSS3引入了一种新的布局模型——flex布局(之前有文章介绍过).flex是flexible box的缩写,一般称之为弹性盒模型.和 ...
- 若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet(转载)
若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet 若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet 请将 J ...
- MySQL:INSERT ... UPDATE
在 INSERT 语句末尾指定ON DUPLICATE KEY UPDATE时,如果插入的数据会导致表中的 UNIQUE 索引或 PRIMARY KEY 出现重复值,则会对导致重复的数据执行 UPDA ...
- c# Dictionary 扩展方法
主要用于接口请求,数据转换 #region Dictionary 扩展方法 public static string getString(this Dictionary<string, stri ...
- Java基础——二分法
BinarySearch 二分法查找,顾名思义就是要将数据每次都分成两份然后再去找到你想要的数据,我们可以这样去想,二分法查找很类似与我们平时玩的猜价格游戏,当你报出一个价格时裁判会告诉你价格相对于真 ...
- Java对象序列化为什么要使用SerialversionUID
1.首先谈谈为什么要序列化对象 把对象转换为字节序列的过程称为对象的序列化. 把字节序列恢复为对象的过程称为对象的反序列化. 对象的序列化主要有两种用途: 1) 把对象的字节序列永久地保存到硬盘上,通 ...
- 58.海量bucket优化机制:从深度优先到广度优先
当buckets数量特别多的时候,深度优先和广度优先的原理,图解 假如我们有如下数据数据:每个演员的每个电影的评论. 现在我们的需求是找到前10名的演员所演的电影的评论.这是一个两层聚合题. ...
- springcloud(十四):搭建Zuul微服务网关
springcloud(十四):搭建Zuul微服务网关 1. 2. 3. 4.
- docker CE 的安装
一.Docker CE的安装1.先决条件运行环境:Ubuntu 64位或者其他支持Docker的64位系统运行配置,linux内核版本必须大于 3.10,否则会因为缺少容器运行所需的功能而出错. 2. ...
- Spark在Executor上的内存分配
spark.serializer (default org.apache.spark.serializer.JavaSerializer ) 建议设置为 org.apache.spark.ser ...