111,126
社区成员
发帖
与我相关
我的任务
分享
[TestAttribute("1测试Attribute代码")] //不是说当运行到这个TAtrributes类时,编译器就会查找TestAttribute特性吗?并实例化TestAttribute特性类,可是我在TestAttribute特性类中的构造中写的Console.Write()没执行哦?
class TAtrributes
{
public TAtrributes()
{
Console.WriteLine("2这是Tatrribute类");
}
}
[System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
sealed class TestAttribute : Attribute
{
// See the attribute guidelines at
// http://go.microsoft.com/fwlink/?LinkId=85236
readonly string positionalString;
// This is a positional argument
public TestAttribute(string positionalString)
{
this.positionalString = positionalString;
// TODO: Implement code here
Console.WriteLine(positionalString);
}
public string PositionalString { get; private set; }
// This is a named argument
public int NamedInt { get; set; }
}
TAtrributes i = new TAtrributes();
输出结果为:2这是Tatrribute类 我以为应该是:先是输出 1测试Attribute代码,然后是 2这是Tatrribute类,为什么没出现我说的这种情况呢?