说的通俗些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的区别的更多相关文章

  1. C#中Property和Attribute的区别

    C#中Property和Attribute的区别 Attribute 字段Property 属性(get;set;) 属性的正常写: private string name; public strin ...

  2. C#中 property 与 attribute的区别?

    C#中 property 与 attribute的区别?答:attribute:自定义属性的基类;property :类中的属性

  3. DOM 中 Property 和 Attribute 的区别

    原文地址:http://web.jobbole.com/83129/ property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute: ...

  4. [转]DOM 中 Property 和 Attribute 的区别

    angular的文档: https://angular.io/guide/template-syntax#property-binding https://blog.csdn.net/sunq1982 ...

  5. JavaScript 中 Property 和 Attribute 的区别详解

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...

  6. DOM 中 Property 和 Attribute 的区别(转)

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...

  7. JS中property与attribute的区别

    property与attirbute都是属性的意思,在JS中很容易混淆,但实际上二者有很大的区别.简单来说, property:是DOM中的属性,是JavaScript中的对像 attribute:是 ...

  8. DOM中 property 和 attribute 详解

    被问到 property 和 attribute 的区别,想来也是要好好看一下. 一.基本概念区别 其实Attribute和Property这两个单词,翻译出来都是“属性”,<js高级程序设计& ...

  9. Property 和 Attribute 的区别(转)

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...

随机推荐

  1. JDBC 中preparedStatement和Statement区别

    一.概念 PreparedStatement是用来执行SQL查询语句的API之一,Java提供了 Statement.PreparedStatement 和 CallableStatement三种方式 ...

  2. 支持flash in Chrome 2017

    在设置页面: chrome://settings/content 修改Flash插件的使用方式为:Allow sites to run Flash 来源: https://helpx.adobe.co ...

  3. Java并发编程75个问答

    1.在java中守护线程和本地线程区别? java中的线程分为两种:守护线程(Daemon)和用户线程(User). 任何线程都可以设置为守护线程和用户线程,通过方法Thread.setDaemon( ...

  4. 20165205 2017-2018-2 《Java程序设计》课程总结

    20165205 2017-2018-2<Java程序设计>课程总结 每周作业链接总结 预备作业一: 简述了我认为好的师生关系,展望了未来学习java的日子 预备作业二:总结了C语言的学习 ...

  5. 在线安装TIDB集群

     在线安装TiDB集群 服务器准备 说明:TiDB8需要能够连接外网,以便下载各类安装包 TiDB4非必须,但最好是有一台,因为后续测试Mysql数据同步或者进行性能比较时,都要用到 TiKV最好是采 ...

  6. mac 安装软件

    一.安装spark 1.官网下载最新tar文件 2.解压 3.安装java开发环境 3.1.安装下载java 8  https://www.oracle.com/technetwork/java/ja ...

  7. Resttemplate中设置超时时长方法

    为了满足调用需求,需要在使用Resttemplate发送请求时,修改超时时长,网上给出了相关修改方法,代码如下: HttpComponentsClientHttpRequestFactory rf = ...

  8. txt,csv,json互相转化

    也没啥,记下来怕忘了.说明都在代码里面: 麻蛋,这个着色好难看 import csv import json #从txt变为csv student_txt=[]; with open("st ...

  9. linux查看磁盘大小df命令

    df -h https://www.cnblogs.com/sparkdev/p/9273094.html

  10. 前端 搜索样式 html

    原文:https://blog.csdn.net/linlinxie/article/details/77484214?utm_source=blogkpcl4 测试1: <div class= ...