Asp.net Control: Properties

12/02/2009

Property packaged component state is rapid application development (RAD) nature. They allow users to custom design-time environment for components. The construction of the property in Visual Basic to support several versions, but not provided by an object, such as C, Java object-oriented programming language. (In the JavaBeans properties is to support an indirect access method adhere to a naming convention.) Is. NET Framework brings RAD Data Communications to simplify object-oriented programming support as a world-class programming construct object properties.

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 such as areas that are accessible through fieldlike pension but implemented using accessor methods. The following example shows a simple construction that specifies a property name public property in class Person:
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.

Attribute can be defined get and set accessors, or just a single access device. Only get access to an attribute is a read-only attribute, and only set accessor attribute is a write-only property. Although the CLR allows write-only attribute. NET Framework Design Guidelines to stop them. If your component requires a write-only property, you should implement a method, rather than the property provide the same 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 can not directly access methods, they are semantically equivalent method. In addition, they can perform any program logic, is covered, and throw an exception. In the next two sections, we will tell you how to override the property and property accessor of value for examination.

Posted in: asp.net| Tags: Programming string Property person name class value asp construction rad

in .NET, some strings will have the same hash code

05/25/2009

 Console.WriteLine("0.89265452879139".GetHashCode());
Console.WriteLine("0.280527401380486".GetHashCode());

Do you know what will happen? Have a try:

2060653827

2060653827

these 2 string share the same hash code!

Posted in: C# and .NET| Tags: NET C# Hash Hashcode string GetHashCode Code color class span pre style

Hot Posts

Latest posts

Tags

Others

Sponsors

asp.net interview questions