Default value of a property

Posted by Nishithraj under Others category on | Views : 1889
We can fix the default value of a property through the code given below.

It will be very useful to avoid the null exceptions while updating to the database. For example if there is a field Acive in data base and it is a notnull field. What will happen if there is no value passed for the property Active from the dotnet part.

We can avoid this by using the Default value attribute as follows.

Private MyVar as Boolean = False
<DefaultValue(False)> _
Public Property Active() As Boolean
Return MyVar
End Get
MyVar = Value
End Set
End Property

private bool myVal=false;

public bool Active {
get {
return myVal;
set {

Comments or Responses

Login to post response