.cs文件里的[]表示什么?看别人的aspx.cs里的文件时 偶尔都会见到[xxxxx] 的写法
这表示什么呢?可以肯定不是数组大概是这样的
[ToolboxData]
{
public class Lists:System.UI.WebControls.WebControl
}

解决方案 »

  1.   

    Attribute 类包含用于访问和测试自定义属性的简便方法。虽然任何用户定义的类型均可用作属性,但大多数属性应当是从 Attribute 派生的类型的实例。所有属性均直接或间接地从 Attribute 派生。属性可应用于任何目标元素(请参见 AttributeTargets);一个属性的多个实例可应用于同一个目标元素;并且属性可由从目标元素派生的元素继承。编译器和其他开发工具利用这些信息来标识哪些属性是自定义属性。自定义属性可与元数据的任何元素一起存储。此机制可用于在编译时存储应用程序特定的信息,并在运行时或在其他工具读取元数据时访问这些信息。.NET Framework 预定义了一些属性类型并使用它们控制运行时行为。某些语言预定义了一些属性类型来表示 .NET Framework 通用类型系统中未直接表示的语言功能。用户或其他工具可以随意定义和使用其他的属性类型。using System;
    using System.Reflection;namespace CustomAttrCS {
        // An enumeration of animals. Start at 1 (0 = uninitialized).
        public enum Animal {
            // Pets.
            Dog = 1,
            Cat,
            Bird,
        }    // A custom attribute to allow a target to have a pet.
        public class AnimalTypeAttribute : Attribute {
            // The constructor is called when the attribute is set.
            public AnimalTypeAttribute(Animal pet) {
                thePet = pet;
            }        // Keep a variable internally ...
            protected Animal thePet;        // .. and show a copy to the outside world.
            public Animal Pet {
                get { return thePet; }
                set { thePet = Pet; }
            }
        }    // A test class where each method has its own pet.
        class AnimalTypeTestClass {
            [AnimalType(Animal.Dog)]
            public void DogMethod() {}        [AnimalType(Animal.Cat)]
            public void CatMethod() {}        [AnimalType(Animal.Bird)]
            public void BirdMethod() {}
        }    class DemoClass {
            static void Main(string[] args) {
                AnimalTypeTestClass testClass = new AnimalTypeTestClass();
                Type type = testClass.GetType();
                // Iterate through all the methods of the class.
                foreach(MethodInfo mInfo in type.GetMethods()) {
                    // Iterate through all the Attributes for each method.
                    foreach (Attribute attr in 
                        Attribute.GetCustomAttributes(mInfo)) {
                        // Check for the AnimalType attribute.
                        if (attr.GetType() == typeof(AnimalTypeAttribute))
                            Console.WriteLine(
                                "Method {0} has a pet {1} attribute.", 
                                mInfo.Name, ((AnimalTypeAttribute)attr).Pet);
                    }            }
            }
        }
    }