博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# Attribute 用法备忘
阅读量:7244 次
发布时间:2019-06-29

本文共 1027 字,大约阅读时间需要 3 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace MyFirstAttribute{    class Program    {        static void Main(string[] args)        {            System.Reflection.MemberInfo info=typeof(TestClass);            MyAttribute myAttribute = Attribute.GetCustomAttribute(info, typeof(MyAttribute)) as MyAttribute;            Console.WriteLine(myAttribute.Author);            Console.WriteLine(myAttribute.Time);            Console.ReadLine();        }    }    #region MyAttribute    [AttributeUsage(AttributeTargets.Class)]    public class MyAttribute : Attribute    {        private string _author;        private string _time;        public MyAttribute(string author, string time)        {            _author = author;            _time = time;        }        public string Author        {            get { return _author; }        }        public string Time        {            get { return _time; }        }    }    #endregion    [My("zzy", "2009-3-3")]    class TestClass    {    }}

 

转载地址:http://hlybm.baihongyu.com/

你可能感兴趣的文章
DELL1320笔记本BIOS升级
查看>>
系统的融合变化感想
查看>>
我的友情链接
查看>>
轻量级开源博客兼CMS系统LBlog发布
查看>>
天气预报的城市三级滚轮的城市表
查看>>
SqlServer2005连接Oracle方法
查看>>
C函数的调用过程 栈帧
查看>>
为什么Maven会更改Eclipse JDK设置
查看>>
疯狂java学习笔记1113---List接口
查看>>
wdlinux centos 7 gearman安装
查看>>
委托delegate
查看>>
Tomcat, Jre 证书相关
查看>>
Magento EasyTabs
查看>>
EDM邮件群发如何高效获取邮件列表?
查看>>
visual studio 2015生成64位DLL文件
查看>>
java.lang.LinkageError
查看>>
Python print函数用法,print 格式化输出
查看>>
C#中实现模拟鼠标事件
查看>>
WPF-14:绑定中数据模型必须为public问题
查看>>
解决Android Studio 和 Android SDK Manager 无法在线更新的问题.
查看>>