This c# and c# net site aims to provide book reviews and free ebook on c# datagrid, c# array, c# xml, msdn c#, c# application, c# example, c# form, c# sample, c# programming, asp net c#,c# database, c# console, c# library, c# file, c# enum, c# switch and c# code, etc.

A Comprehensive Guide to C# and the .NET Platform

©2001 Andrew Troelsen
Advanced C# Class Construction Techniques
This chapter rounds out your introduction to the core aspects of the C# language by examining a number of advanced (but extremely useful) syntactic constructs. To begin, you learn how to construct and use an indexer method. This C# mechanism enables you to build custom types, which exposes internal subtypes using the familiar bracket operator (i.e., []). If you have a C++ background, you will find that creating a C# indexer method is analogous to overloading the [] operator on a C++ class. Once you learn how to build an indexer, you then examine how to overload various operators (+, -, <, > and so forth) for a custom C# type.
This chapter then examines three techniques that enable the objects in your system to engage in bidirectional communications. First, you learn about the C# “delegate” keyword, which is little more than a type-safe function pointer. Once you learn how to create and manipulate delegates, you are in a perfect position to investigate the .NET event protocol, which is based on the delegation model. Finally, you discover how the use of custom interfaces can also enable bidirectional communications (which should ring a bell for those coming from a COM background).
I wrap up by examining how you can document your types using XML attributes, and how the Visual Studio.NET IDE automatically generates Web-based documentation for your projects. Although this might not qualify as a truly “advanced” technique, it is a high note on which to end the chapter.