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 ...
随机推荐
- 解决Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject.
见https://blog.csdn.net/qq_21397217/article/details/65630730博客
- ubuntu下安装owncloud提示没有zip模块时
wget http://pecl.php.net/get/zip-1.13.5.tgztar -zvxf zip-1.13.5.tgzcd zip-1.13.5phpize ./configure m ...
- JS高级-ES6
let/const case1 { //js var a = 10 a = 20 // es6 let b = 10 b = 30 const c = 10 c = 40 //报错 } case2 { ...
- oracle之分析函数解析及其应用场景
ORACLE 分析函数FIRST_VALUE,LAST_VALUE用法sum overavg over first_value overlast_value over...聚合函数结合over就是分析 ...
- Python有趣时刻,这些代码让你大呼"卧槽,怎么会这样"
分享一个实用问题,用python读取Excel并保存字典,如何做? 下面是该同学问题截图和代码 image.png 代码截图是下面这样的 image.png 不知道大家第一眼看了这个代码,什么感受?我 ...
- SpringBoot 之 thymeleaf
thymeleaf 的maven 配置我们都知道: <dependency> <groupId>org.springframework.boot</groupId> ...
- 如何查看java的class文件
1.首先拿到javac文件 例如:test.class 2.可以使用文本编辑器用二进制的方式打开() cafe babe 0000 0034 0056 0a00 1200 3209 0010 0033 ...
- leetcode42
class Solution: def calLeft(self,height,rightval,left,right): if left>=right: return 0 sums = 0 m ...
- 移动端UL列表无法平滑向下滚动问题
问题说明: 移动端向上滑动后,,列表无法自动滚动到底部~~而是类似屏幕"沾手"的效果(手离开屏幕直接停止在当前~列表不会自动向下滚动一段) 问题原因: 页面中存在如下代码: 当前页 ...
- 基于windows平台搭建elasticsearch
部署准备 elasticsearch-6.0.1.zip--https://www.elastic.co/downloads/elasticsearch elasticsearch-head-mast ...