欢迎光临极品网,更多、更新的资源信息尽在Jpinw.Com!本站所有信息资源每日更新新的内容,请大家继续关注www.Jpinw.com!如果觉得本站还不错,对您有帮助,别忘了向您的朋友推荐本站!请记好本站网址:http://www.Jpinw.com,网站发展靠大家多多的支持!!!

极品网 极品课件 极品论文 极品文学 极品游戏 极品美容 极品手机资源 极品股票

#
免费资源: 免费域名 | 免费空间 | 免费推广 | 免费邮箱 | 免费硬盘 | 免费论坛 | 免费留言 | 免费统计 | 在线投稿 | 更多...
电脑学院: 操作系统 | 安全相关 | 网页设计 | 编程开发 | 建站经验 | 服务器类 | 黑客攻防 | 菜鸟入门 | 教你网赚 | 更多...
文章导航: 网赚学堂 | 网赚秘笈 | 网赚三维 | 网赚先锋 | 网赚资讯 | 感悟网赚 | 众生百态 | 经典美文 | 范文中心 | 更多...
图酷天下: 时事图酷 | 娱乐图酷 | 搞笑图酷 | 时尚图酷 | 体育图酷 | 另类经典 | 论文资源 | 课件下载 | 文学知识 | 更多...

您现在的位置: 极品网 >> 电脑学院 >> 编程开发 >> 编程综合 >> 教程正文

(FxCop.设计规则)1. 抽象类不应该拥有构造函数            【字体:
(FxCop.设计规则)1. 抽象类不应该拥有构造函数
作者:佚名    教程来源:不详    点击数:    更新时间:2008-1-1    

 








(FxCop.设计规则)1. 抽象类不应该拥有构造函数。 1. 抽象类不应该拥有构造函数原文引用:Abstract types should not have constructors
TypeName:
AbstractTypesShouldNotHaveConstructors
CheckId:
CA1012
Category:
Microsoft.Design
Message Level:
CriticalWarning
Certainty:
95%
Breaking Change:
NonBreaking
Cause: A public type is abstract and has a public constructor.
Rule Description
Constructors on abstract types can only be called by derived types. Because public constructors create instances of a type, and you cannot create instances of an abstract type, an abstract type with a public constructor is incorrectly designed.
How to Fix Violations
To fix a violation of this rule, either make the constructor protected, or do not declare the type as abstract.
When to Exclude Messages
Do not exclude a message from this rule.
Example Code
The following example contains an abstract type that violates this rule, and an abstract type that is correctly implemented.

[C#]
using System;
namespace DesignLibrary
{
public abstract class BadAbstractClassWithConstructor
{
// Violates rule: AbstractTypesShouldNotHaveConstructors.
public BadAbstractClassWithConstructor()
{
// Add constructor logic here.
}
}
public abstract class GoodAbstractClassWithConstructor
{
protected GoodAbstractClassWithConstructor()
{
// Add constructor logic here.
}
}
}
引起的原因:一个公共抽象类型拥有一个公共的构造函数描述:构造函数被用来建立一个对象实例,但是你不能建立一个抽象类型的实例,抽象类型的构造函数就仅仅能够被它的继承类型使用。因此,为一个抽象类构造公共构造函数是一个错误的设计。修复:如果需要修复这个问题,可以声明这个构造函数为保护型,或者,声明这个类型不是一个抽象类型。
<

 

教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关教程
    使用SqlBulkCopy进行大批量数
    ASP.NET: Connection String
    ASP.NET: HtmlEncode/UrlEnc
    asp+中的session 的使用和原
    Aspect-Oriented Programmin
    Aspx中导Excel
    asp+ 操作Cookie 方法大全
    Asp.Net页面输出到EXCE
    Asp.Net中DataGrid的模版列(
    Asp.Net下导出/导入规则的Ex
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    极品网
    | 设为首页 | 加入收藏 | 友情链接 | 版权声明 |
    极品网

    Copyright 2006 Jpinw.com 极品网

    备案号:浙ICP备07010375号

    极品网