csharp System.ComponentModel.DefaultValueAttribute类(方法)实例源码

下面列出了csharp System.ComponentModel.DefaultValueAttribute 类(方法)源码代码实例,从而了解它的用法。

作者:.NET开发    项目:System.ComponentMode   
private bool _myVal = false;

[DefaultValue(false)]
public bool MyProperty
{
    get
    {
        return _myVal;
    }
    set
    {
        _myVal = value;
    }
}

作者:.NET开发    项目:System.ComponentMode   
// Gets the attributes for the property.
AttributeCollection attributes =
    TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

/* Prints the default value by retrieving the DefaultValueAttribute 
 * from the AttributeCollection. */
DefaultValueAttribute myAttribute =
    (DefaultValueAttribute) attributes[typeof(DefaultValueAttribute)];
Console.WriteLine("The default value is: " + myAttribute.Value.ToString());


问题


面经


文章

微信
公众号

扫码关注公众号