Free Online Articles Directory
17.11.2008 Sign In Register Hello Guest
Email:
Password:
Remember Me 
forgot your password?


Asp.net Control: Properties

Author: tommk Author Ranking Blue | Posted: 25-02-2008 | Views: 26 | Rating:  (52) Article Popularity - Blue (?) Got a Question? Ask.
Sign Up Now!

Properties encapsulate the state of a component and are the essence of rapid application development (RAD). They allow users to customize components in a design-time environment. The property construct has been supported in Visual Basic for several editions but is not offered by object-oriented programming languages such as C++ and Java. (Properties in JavaBeans are supported indirectly by adherence to a naming convention for accessor methods.) The .NET Framework brings the ease of RAD programming to the object-oriented world by supporting properties as a first-class object-oriented programming construct.

We'll look at the property construct first. Then we'll look at naming guidelines for properties and the advantages of exposing properties.

The Property Construct
Properties are like smart fields that are accessed using fieldlike syntax but implemented using accessor methods. The following example illustrates a simple property construct that defines a Name public property in the Person class:
public class Person {
// The private field below is not part of the property
// construct but contains data that holds the value of
// the Name property.
private string _name;
public string Name {
get {
return _name;
}
set {
_name = value;
}
}
}

The boldface elements—get, set, and value—are keywords in the C# property syntax. The compiler transforms the code in the get and set blocks into methods that are called property accessors. The get accessor—also called the getter—retrieves the value of the property, while the set accessor—also called the setter—assigns a value to the property. The value identifier denotes the implicit parameter that is passed into the setter.

C# does not have a keyword named property. However, Visual Basic .NET does use the Property keyword as shown in the following example, which shows the keywords in Visual Basic .NET property syntax in boldface:
Private String _name
Public Property Name() As String
Get
Return _name
End Get
Set (ByVal value As String)
_name = value
End Set
End Property

In contrast with C#, value in Visual Basic .NET is not a keyword in property syntax.

Although the get and set accessors are equivalent to methods, they cannot be invoked as methods in C# and Visual Basic .NET but are indirectly accessed by code that assigns or retrieves a property.

The syntax for setting a property is the same as that for setting a field. When you are setting a property, the assigned value must match the declared type of the property:

Person aPerson = new Person();
aPerson.Name = "John"; //Type of Name is string.

The property construct allows you to abstract the storage and implementation of a property from the clients of your component. In our example, a private field holds the data for the Name property. While the backing data for a property is often a private field, the data could reside elsewhere—for example, on disk or in a database—or it could be generated dynamically, as in a property that returns the system time.

A property can define both the get and set accessors or just a single accessor. A property with only a get accessor is a read-only property, while a property with only a set accessor is a write-only property. Although the CLR allows write-only properties, the design guidelines for the .NET Framework discourage them. If your component needs a write-only property, you should implement a method instead of a property to provide the equivalent functionality.

A property can have any access level allowed by the runtime, including public, private, protected, or internal. In C# and Visual Basic .NET, the access level of a property applies to both accessors; it is not possible to have a different access level for each accessor.

Although the get and set accessors are not directly accessible as methods, they are semantically equivalent to methods. Furthermore, they can perform any program logic, be overridden, and throw exceptions. In the next two sections, we'll show you how to override a property and perform value checking in a property accessor.

Rate this Article: Current: 0 / 5 stars - 0 vote(s).

Article Tags: Asp.net

Article Source: http://www.articlesbase.com/programming-articles/aspnet-control-properties-340927.html

Print this Article Print article   Email to a Friend Send to friend   Publish this Article on your Website Publish this Article   Send Author Feedback Author feedback  
About the Author:

more info

Submitting articles has become one of the most popular means to drive traffic to your website and promote yourself and your business. Join us today - It's Free!

Related Articles

Optimizing Your Asp.Net Pages for Faster Loading and Better Performance.
By: John Belthoff | 27/04/2006 | Programming
If you read the internet and all of the websites dedicated to Asp.Net you will inevitably read about the wonders of the DataGrid, DataList, and Repeater controls. While each of these has its place, if you are only displaying data there is a much faster and more efficient means to do so.

Url Rewriting in Asp.net With Sample Project
By: joggee | 27/06/2008 | Programming
URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL. To understand completely follow below link http://msdn.microsoft.com/en-us/library/ms972974.aspx In this article I am going make a simple example which will take only few minutes and you will learn how to achieve URL Rewriting. I believe developer doesn’t have much time to read a complete article of 20 pages.

Web Languages: Php Vs. Asp.net
By: Kevin Jordan | 10/11/2006 | Programming
While the average web developer has a lot of options these days. It's really more of a bi-partisan system between ASP.NET and PHP, the rest being just independents. The battle rages between the supporters of the two languages, with no clear winner every coming out. While both can be used to complete the same project, it really depends on what you're looking for: price, speed, security, etc.

How to Create a Data Source in Visual Studio.net
By: ProgrammingHelp.com | 27/06/2008 | Programming
This detailed article by James will tell you how to create a Data Source in Visual Studio .NET, along with easy-to-follow screenshots that guide you along the way.

An Affordable Web Site Design and Development Services
By: MAHI Infobase | 06/01/2007 | Internet
WEll we are doing web site design and development in an affordable price! And aslo doing Web Designing,Application development, Web Development, Logo design, flash websites, Asp.net, ASP, PHP, LAMP programming, Database design.

Why Use Asp.net, and the Basics With Visual Studio 2008 Express Edition
By: D R Haake | 16/07/2008 | Programming
ASP.Net is a great technology to deploy a new website. There are a couple of drawbacks, but these can be overcome by using Visual Studio 2008 Express Edition. This allows you to create uniform websites quickly and easily and manage your website's content in an easy-to-use manner that many novice web developers can easily get accustomed to.

Outsourcing Craze in India
By: Maggie Tran | 14/06/2007 | Outsourcing
Outsourcing is Become a Part Of The Business as well as Today’s global marketplace outsourcing has made itself accessible to many organizations on a national and international level

Installing Ajax Toolkit for Visual Studio .net 2005
By: Programminghelp.com | 08/08/2008 | Programming
In this article I will explain how you can integrate the AJAX framework into a web site and very easily create an AJAX enabled web site within Visual Studio 2005 utilizing C#.

Got a Question? Ask.

Ask the community a question about this article:

Frequently Asked Questions

I want websites use the GNU Free Documentation License
By: HappyRebecca | 04-11-2008
Does anyone know which websites(the content is about DIY, how-to, recipes...) use the GNU Free Documentation License? Thanks a lot~

How do i install a third party application Ovr ...
By: kevin | 03-11-2008
How do i install a third party application Ovr the air for a blackberry which does not run on a BES?

How do we put this in apa style references ...
By: Crystal | 02-11-2008
how do we put this in apa style references Hopelessness: A Dangerous Suicide Warning Signs

I have a palm centro. my mom threw away the whole ...
By: WiZardOfTheHOOD | 02-11-2008
i have a palm centro. my mom threw away the whole box that came with it and i'm pretty sure she had the internet blocked because i couldn't pick up connection at my clubhouse. i have the cord that connects my phone to the laptop and i'm wondering how i can use my laptops internet on my palm centro.

Bluetooth set up of wireless internet access on my Mac thru T-mobile
By: juristman | 01-11-2008
How do I set up wireless internet access on my Mac computer through Bluetooth on my Nokia cell phone with T-Mobile? psbaer@comcast.net

What command is used to check whether the client ...
By: Hiren | 01-11-2008
What command is used to check whether the client has put the port in integer?

Q&A Powered by:
Powered by Yedda 

Latest Programming Articles

Mvc Design Pattern
By: TuVinhSoft .,JSC | 14/11/2008
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (View) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface.

Advantages of Low Cost Contract Programmers in Freelance Programming
By: Joanna Gadel | 12/11/2008
It observed that web industry is getting tougher thus the necessity of freelance contract programmer is required for developing more effective website with flexible features. This article states the fruitful advantages of freelance programmers in contract programming.

A Guide to Cnc Kits
By: Martin Applebaum | 09/11/2008
CNC kits are a way in which to construct your CNC machine. This article will provide some information on these machines.

A Guide to Cnc Tube Bending Machines
By: Martin Applebaum | 08/11/2008
Are you familiar with a CNC tube bending machine? This article will shed some light on the main function and components of this machine.

Ways to Hire Dedicated Php Programmers
By: Jucick | 08/11/2008
It’s not at all easy to hire dedicated PHP programmers unless you know where and how to find them. Whether you need to fix, update or enhance your website you naturally want the job done quick and right.

Top 4 Reasons Why Addressing Web Accessibility is Important
By: Matt Cave | 05/11/2008
There are very high chances that web accessibility is more important to the performance of your web site than you realize. Article takes a look at the top 4 reasons why it would be important to address the issue of web accessibility.

Xlphoto Printing, the Best Choice for Banner Printing and Poster Printing
By: Vikram Kumar | 01/11/2008
Suppose, you have visited a tourist spot or a hill station; over there, you have witnessed some of the mesmerizing locations of serene nature.

Simple & Complete Gridview Functionality(dotnet 2.0) by Syed Shees Abidi
By: Shees Abidi | 31/10/2008
My this article covers GridView functionality in a Complte,Simple & Precise way in ASP.NET(2.0),C#,SQLServer 2005.This article provides a single GridView which is capable of ~Displaying Data ~Updating it ~Deleting the existing records from database based on a Confirmation Message and ~Inserting a new record(which is beyond the implicit usage of GridView). NOTE: The application requires three simple stored proc. named empins,empupd,empdel for updation insertion and deletion respectively

Article Categories





Give Feedback

Sign up for our email newsletter

Receive updates, enter your email below