In Brief

This chapter explained how to use operator overloading and conversions, delegates and events, attributes and interfaces.

  • Operator overloading enables you to build types that have a more meaningful interface with custom operators. The primary purpose of operator overloading is to create types with semantics similar to the built-in types. Conversion operators specify how casts between types may be performed.

  • Delegates are objects that reference methods. They make it easy for a program to pass around references to methods and provide a way to invoke methods dynamically at runtime. Events are for supporting GUI interaction with a user or notifying other interested classes when something happens to invoke the event. For example, a Windows Forms button-click generates an event that different parts of your program may want to catch. The mechanism of hooking up event handlers with events works by assigning a delegate, which specifies an event handler method, to an event. When the event is invoked, the method that the delegate refers to is called.

  • Attributes are for decorating code with special information about a program. They are a declarative form of programming, and depending on the purpose of the attribute, they pass information to the compiler or other tool interested in knowing something about your program. For example, the C# compiler will recognize the Obsolete attribute and issue a warning.

  • Interfaces specify the public members that a type exposes. They are essentially a contract that guarantees to callers that any type inheriting an interface will definitely implement the type members specified by that interface. Interfaces are used throughout the .NET Framework BCL and allow you to do things that would be difficult or impossible without them. For instance, interfaces enable operation of collection iteration in the foreach loop. The IDisposable interface enables the Dispose pattern, which is the primary means of implementing deterministic destruction in C#. Interfaces contribute to well-engineered and robust code.



C# Builder KickStart
C# Builder KickStart
ISBN: 672325896
EAN: N/A
Year: 2003
Pages: 165

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net