.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Default value of a property

Posted By:nishithraj       Posted Date: March 26, 2010    Points: 10    Category: Silverlight    URL: http://www.dotnetspark.com  

Default value of a property
 

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

 _

Public Property Active() As Boolean

    Get

        Return MyVar

    End Get

    Set

        MyVar = Value

    End Set 

End Property







private bool myVal=false;



[DefaultValue(false)]

 public bool Active {

    get {

       return myVal;

    }

    set {

       myVal=value;

    }

 }
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend