Skip to content

Set default value to a property

February 22, 2010

Hello !

Just a few days back I found out that setting default values to a property is very simple, Just follow the steps mentioned below -

  1. Make sure that you are using System.ComponentModel – (using System.ComponentModel;)
  2. Set the [DefaultValueAttribute("")] before the property

e.g.

[DefaultValueAttribute("")]
public string Website
{
get { return m_website; }
set { m_website = value; }
}

DefaultValueAttribute accepts various parameters, Use the desired one.

Advertisement

From → asp.net

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.