C#的特性在继承类中不会被继承吗? 我想问高手一个问题,C#类的特性(如[STAThread()])。我如果继承了这个类,请问这个特性会被继承下去吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Ok,现在我们来讨论一下最后的这个属性。Inherited, 表明当特性被放置在一个基类上时,它能否被派生类所继承。[Help("BaseClass")] publicclass Base{} publicclass Derive : Base{} 这里会有四种可能的组合:[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true ] 第一种情况:如果我们查询(Query)(稍后我们会看到如何在运行期查询一个类的特性)Derive类,我们将会发现Help特性并不存在,因为inherited属性被设置为false。第二种情况:和第一种情况相同,因为inherited也被设置为false。 第三种情况:为了解释第三种和第四种情况,我们先来给派生类添加点代码:[Help("BaseClass")] publicclass Base{}[Help("DeriveClass")] publicclass Derive : Base{} 现在我们来查询一下Help特性,我们只能得到派生类的属性,因为inherited被设置为true,但是AllowMultiple却被设置为false。因此基类的Help特性被派生类Help特性覆盖了。第四种情况:在这里,我们将会发现派生类既有基类的Help特性,也有自己的Help特性,因为AllowMultiple被设置为true。 C#如何将数据一条一条的加入临时表! 为什么我写了没有自动提示的功能,跪求! asp.net2.0调用非托管代码问题,请各位指教&&尝试读取或写入受保护的内存。这通常指示其他内存已损坏 winform中刷新label控件 c#aspx.cs中我加入发邮件代码,报错,求大神看看 郁闷呀,发了几个贴子,没人回,白白浪费了几百分。呜呜呜 C# 如何遍历一个文件夹下的所有txt文档,并显示出来 请教一主细表关系问题 最菜的菜鸟学c#,从何处着手(本人没语言基础)!!!是个难题!~~~:) 怎么注册呢??? 逻辑规律问题 通过RS232实现拍照
这里会有四种可能的组合:[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false ]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false ]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true ]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true ]
第一种情况:如果我们查询(Query)(稍后我们会看到如何在运行期查询一个类的特性)Derive类,我们将会发现Help特性并不存在,因为inherited属性被设置为false。第二种情况:和第一种情况相同,因为inherited也被设置为false。 第三种情况:为了解释第三种和第四种情况,我们先来给派生类添加点代码:[Help("BaseClass")] publicclass Base{}[Help("DeriveClass")] publicclass Derive : Base{}
现在我们来查询一下Help特性,我们只能得到派生类的属性,因为inherited被设置为true,但是AllowMultiple却被设置为false。因此基类的Help特性被派生类Help特性覆盖了。第四种情况:在这里,我们将会发现派生类既有基类的Help特性,也有自己的Help特性,因为AllowMultiple被设置为true。