|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DefaultValueAttribute usageI have a number of questions regarding the DefaultValueAttribute which
is not explained in the rather terse MSDN documentation for it: 1) Should I use it for all properties, even when the property is initialized to its equivalent 0 value and I do not specifically initialized in the constructor of my component in which the property resides ? 2) Is the default value always a constant expression ? 3) Is it used for reference types ? How ? A reference type is not a constant value. 4) Can it be used for enumerated types ? How ? Is the constructor taking an Object applied when used for an enumerated type ? 5) Can it be used for the string type, which is a reference type, passing it a string constant ? Edward,
>1) Should I use it for all properties, even when the property is Yes>initialized to its equivalent 0 value and I do not specifically >initialized in the constructor of my component in which the property >resides ? >2) Is the default value always a constant expression ? Well it has to be if you want to use the DefaultvalueAttribute.>3) Is it used for reference types ? How ? A reference type is not a string is a reference type, so yes.>constant value. >4) Can it be used for enumerated types ? How ? Is the constructor taking I believe so.>an Object applied when used for an enumerated type ? >5) Can it be used for the string type, which is a reference type, See 3.>passing it a string constant ? Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. |
|||||||||||||||||||||||