DefaultValueAttribute usage

  • Thread starter Thread starter Edward Diener
  • Start date Start date
E

Edward Diener

I 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
initialized to its equivalent 0 value and I do not specifically
initialized in the constructor of my component in which the property
resides ?
Yes


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
constant value.

string is a reference type, so yes.

4) Can it be used for enumerated types ? How ? Is the constructor taking
an Object applied when used for an enumerated type ?

I believe so.

5) Can it be used for the string type, which is a reference type,
passing it a string constant ?

See 3.


Mattias
 
Back
Top