Sponsored Ad

Friday, October 23, 2009

C# Function Members

Role membership is the members provide some functionality for handling data
kind. This includes methods, properties, constructors, finalizers, operators and indexers. Methods are functions that are associated with a particular class. They can be instance methods, working in a particular instance of a class or static methods, which provide more generic functionality that does not require a class instance (eg Console.WriteLine () method). Methods are discussed in the next section.

Properties are sets of functions that can be accessed from the client in a similar way to the public fields ofthe class. C# provides a specific syntax for implementing read and write properties on your classes, so you don ’ t have to jury - rig methods whose names have the words Get or Set embedded in them.
Because there ’ s a dedicated syntax for properties that is distinct from that for normal functions, theillusion of objects as actual things is strengthened for client code.

Constructors are special functions that are called automatically when an object is instantiated. They musthave the same name as the class to which they belong and can't have a return type. Constructors areuseful for initializing the values of fields.

Finalizers are similar to the builders, but is called when the CLR detects that an object is no longer necessary. They have the same name as the class, preceded by a tilde (~). C + + must take into account finalizers that are used much less frequently in C # that is closest to C + + destructors equivalent, because the CLR handles garbage collection automatically. Furthermore, it is impossible to predict accurately when a finalizer will be called. Finishers are discussed in Chapter 12, "Memory Management and pointers.

The operators, in its simplest form, are actions such as + or -. When you add two integers, which are, strictly speaking, using the + operator for integers. However, C # also allows you to specify how existing operators work with their own classes (operator overloading). Chapter 6, "Operators and casts," looks at the operators in detail.

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers