C#中 property 与 attribute的区别
说的通俗些Attribute是类,不过是一类比较特殊的类,Attribute必须写在一对方括号中,用来处理.NET中多种问题:序列化、程序的安全特征等等,在.NET中的作用非同凡响
Attribute的目的是为元素提供关联附加信息。
1.自定义Attribute类:VersionAttribute
[AttributeUsage(AttributeTargets.Class)]
public class VersionAttribute : Attribute
{
public string Name { get; set; }
public string Date { get; set; }
public string Describtion { get; set; }
}
2.使用自定义Attribute的Class:
[Version(Name = "hyddd", Date = "2009-07-20", Describtion = "hyddd's class")]
public class MyCode
{
//...
}
Property可以说是一个面向对象的概念,提供了对私有字段的访问封装,在C#中以get和set访问器方法实现对可读可写属性的操作,提供了安全和灵活的数据访问封装。比如:
public class Robot
{
private string name = ""; //字段:Field
public string Name //属性:Property,对Field进行封装。
{
get { return name; }
set { name = value; }
}
}
C#中 property 与 attribute的区别的更多相关文章
- C#中Property和Attribute的区别
C#中Property和Attribute的区别 Attribute 字段Property 属性(get;set;) 属性的正常写: private string name; public strin ...
- C#中 property 与 attribute的区别?
C#中 property 与 attribute的区别?答:attribute:自定义属性的基类;property :类中的属性
- DOM 中 Property 和 Attribute 的区别
原文地址:http://web.jobbole.com/83129/ property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute: ...
- [转]DOM 中 Property 和 Attribute 的区别
angular的文档: https://angular.io/guide/template-syntax#property-binding https://blog.csdn.net/sunq1982 ...
- JavaScript 中 Property 和 Attribute 的区别详解
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...
- DOM 中 Property 和 Attribute 的区别(转)
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...
- JS中property与attribute的区别
property与attirbute都是属性的意思,在JS中很容易混淆,但实际上二者有很大的区别.简单来说, property:是DOM中的属性,是JavaScript中的对像 attribute:是 ...
- DOM中 property 和 attribute 详解
被问到 property 和 attribute 的区别,想来也是要好好看一下. 一.基本概念区别 其实Attribute和Property这两个单词,翻译出来都是“属性”,<js高级程序设计& ...
- Property 和 Attribute 的区别(转)
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...
随机推荐
- 20165312 2017-2018-2 《JAVA程序设计》第2周学习总结
20165312 2017-2018-2 <JAVA程序设计>第2周学习总结 一.对上一周学习的查漏补缺 1.上周在虚拟机中进行编译程序时出现错误,在上一周的博客中我有提到,当时还未找到解 ...
- sharepoint环境安装过程中几点需要注意的地方
写在前面 上篇文章也说明了,在安装sharepoint环境的时候,确实吃了不少苦头,这里纪录一下安装过程中遇到的几个问题. 安装环境 windows server 2012 r2 standard x ...
- 虚拟机安装centOs+网络配置(完整说明)
1.新建虚拟机(标准) 选择 (我以后下安装操作系统) 选择Linux 操作系统 版本为CentOS(32位) 虚拟机的名称和位置任意 磁盘容量如下即可 设 ...
- Java应用常用性能分析工具
Java应用常用性能分析工具 好的工具有能有效改善和提高工作效率或加速分析问题的进度,笔者将从事Java工作中常用的性能工具和大家分享下,如果感觉有用记得投一票哦,如果你有好的工具也可以分享给我 工具 ...
- thinkphp5 Exception类重定义
重点定义自己的错误信息和错误码: 在TP5的配置文件中有下面一段 // 异常处理handle类 留空使用 \think\exception\Handle 'exception_handle' => ...
- RF:操作笔记
1.变量运算
- Mysql 日期加减
mysql表中有一些字段是显示日期的.因为各种需要,需要将它时间往后调整1年. mysql 日期增加一年的更新语句更新的语句如下: UPDATE table SET date = DATE_A ...
- 剑指offer——合并两个排序的链表——对象、引用和赋值初接触
题目描述:输入两个单调递增的链表,输出两个链表合成后的链表,当然,我们需要合成后的链表满足单调不减规则. 先公布结果: /* public class ListNode { int val; List ...
- 2017-11-04 Sa Oct 消参
2017-11-04 Sa $ P(-3, 0) $ 在圆C $ (x-3)^2 + y^2 = 8^2 $ 内,动圆M与圆相切且过P点,求M点轨迹. 设切点 $ A(a, b) $,圆心 \(M(x ...
- oracle in和exist的区别 not in 和not exist的区别
in 是把外表和内表作hash join,而exists是对外表作loop,每次loop再对内表进行查询.一般大家都认为exists比in语句的效率要高,这种说法其实是不准确的,这个是要区分环境的. ...