Properties
As weve seen, properties are characteristics shared by all objects of a particular
class. In the case of our example, the following properties might be used to describe
any given dog:
color
height
length
In the same way, the more useful ASP.NET Button class exposes properties in-
cluding:
Width
Height
ID
Text
ForeColor
BackColor
Unfortunately for me, if I get sick of Raynes color, I cant change it in real life.
However, if Rayne was a .NET object, we could change any of his properties in
the same way that we set variables (although a property can be read-only or write-
only). For instance, we could make him brown very easily:
Visual Basic
rayne.Color = "Brown"
C#
rayne.Color = "Brown";
In this example, were using an instance of our Dog class called rayne. We use
the dot operator (.) to access the property Color that the object exposes and set
it to the string "Brown."
81
Properties

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.