Chapter 5. C in the .NET Framework

for RuBoard

Chapter 5. C# in the .NET Framework

C # as a language is elegant and powerful. To fully use its capabilities you need to understand how it works within the .NET Framework. We begin with the root class object . Collections are examined next , including the methods of the object class that should be overridden to tap into the functionality provided by the .NET Framework. We then introduce interfaces, which allow you to rigorously define a contract for a class or struct to implement. In C# a class can implement multiple interfaces, even though it can inherit from only one class. Interfaces allow for dynamic programming; you can query a class at runtime to see whether it supports a particular interface.

The interfaces supporting collections are examined in detail. We investigate issues involved in copying objects, such as shallow copy and deep copy. Instead of using copy constructors as in C++, in C# you implement the ICloneable interface. We explore generic interfaces in the .NET Framework programming model and compare the .NET and COM component models. A further illustration of generic interfaces is provided by sorting in different orders with the IComparable interface. The examples offer insight into the workings of frameworks, which are more than class libraries. In a framework, you call the framework, and the framework calls you. Your code can be viewed as the middle layer of a sandwich. This key insight can help you grasp what makes .NET programming "tick." While callback functions have been used for years in programming, C# uses this concept in delegates and events. Two simple and intuitive examples are presented: a stock market simulation and an online chat room. The chapter concludes with a discussion of attributes, which are pervasive in the .NET Framework.

for RuBoard


Application Development Using C# and .NET
Application Development Using C# and .NET
ISBN: 013093383X
EAN: 2147483647
Year: 2001
Pages: 158

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