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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

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


        Return MyVar

    End Get


        MyVar = Value

    End Set 

End Property

private bool myVal=false;


 public bool Active {

    get {

       return myVal;


    set {



 Subscribe to Articles


Further Readings:


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