C# class中的attribute和property

C# class中的attribute和property


Microsoft的C#帮助文档中的class包含两个信息。attribute property,中文版均翻译成“属性”。这里严重混淆了2个重要概念。property就是属性,可以通过get,set来访问。和class中另一个概念field“字段”的区别比较明显。

而attribute又代表了什么呢,attribute其实反映了一种继承关系,也就是说该class具有什么样的接口。attribute反应了一种归属,可理解为特征

  1. attribute确定了该对象的type。1个对象可以有多个不同的attribute,不同的对象也可以有相同的attribute。
  2. 在使用某个attribute的接口时,不同的拥有该attribute的class对象可以相互替换。
  3. 对象的class和type是不同的,class是property的集合,可以理解为物理特性。而type是attribute的集合,可以理解为功能属性。
  4. 张三是个男人(class),(能打枪(attribute),能开炮(attribute),能开车(attribute))type。
    李四是个女人(class),(能打枪(attribute))type。
    那么在执行打枪任务的时候,张三和李四是可以相互替换的,这样就增加了灵活性。

Panel 类
定义
命名空间:
System.Windows.Controls
程序集:
PresentationFramework.dll
为所有 Panel 元素提供基类。 使用 Panel 元素放置和排列 Windows Presentation Foundation (WPF) 应用程序中的子对象。
。。。。。
继承
Object
DispatcherObject
DependencyObject
Visual
UIElement
FrameworkElement
Panel
派生
System.Windows.Controls.Canvas
System.Windows.Controls.DockPanel
System.Windows.Controls.Grid
System.Windows.Controls.Primitives.TabPanel
System.Windows.Controls.Primitives.ToolBarOverflowPanel
更多…
属性(这里是attribute)
LocalizabilityAttribute ContentPropertyAttribute

实现
IAddChild

构造函数
Panel()
初始化 Panel 类的新实例。
字段
BackgroundProperty
标识 Background 依赖项属性。
IsItemsHostProperty
标识 IsItemsHost 依赖项属性。
ZIndexProperty
标识 ZIndex 附加属性。
****属性这里是property
ActualHeight
获取此元素的呈现高度。

(继承自 FrameworkElement)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值