首页
|
编程语言
|
网站建设
|
游戏天堂
|
冲浪宝典
|
网络安全
|
操作系统
|
软件时空
|
硬件指南
|
病毒相关
|
IT 认证
软讯网络
>
编程语言
>
.NET
>
C#.NET
> 发现 protected constructor 的无聊的地方.
【标 题】:发现 protected constructor 的无聊的地方.
【关键字】:
protected,constructor
【来 源】:http://blog.joycode.com/lostinet/archive/2004/12/12/41012.aspx
发现 protected constructor 的无聊的地方.
通常一个类的constructor是protected的时候,是不希望用户直接调用它.
但是我发现可以用这么一个方法来实现调用:
public class ClassA { protected ClassA() { } } class ClassX : ClassA { static public ClassA CreateClassA() { return new ClassA(); } }
关于protected成员的调用,以前有类似的blog的.
关于protected的Quiz
protected的成员是不能变相被子类调用的,例如
class ControlUtility : System.Web.UI.Control { public System.Web.HttpContext GetContext(System.Web.UI.Control ctrl) { return ctrl.Context; } }
是不能编译通过的,但constructor却能通过
当然,如果该类是sealed就不行了,那么protected和private也没有区别了.
你的程序支持 IIS6 - Web Garden 吗?
:【上一篇】
用 System.Reflection.Emit 自动实现调用存储过程的接口
:【下一篇】
【相关文章】
constructor in singleton pattern
嵌套对象的copy-constructor
8.7.10 Static constructors
8.7.8 Instance constructors
default constructor
如何得到constructor 和 copy constructor 执行次数
脱壳高级篇之Import REConstructor使用
【随机文章】
SFC更新
iptables 介绍
实验Recordset.Movenext,Recordset.Previous,Recorset...等移动记录
在按需电路上配置OSPF
网易面试题:求连续几个自然数之和为S的序列
WinCE 程序设计 (3rd 版)--2.3 位图
你懂不懂xml!
PhotoImpact环境介绍
百度MP3批量下载<免去了在网页上多次点击链接才能下载一首歌曲的痛苦。>
Linux 指令篇:档案目录管理--less
【相关评论】
没有相关评论
【发表评论】
姓名:
邮件:
随机码
*
:
评论
*
:
|
首 页
|
版权声明
| 联系我们
|
网站地图
|
CopyRight © 2004-2007
b
b
b
软讯网络 All Rigths Reserved.