Summary


In this chapter, we've seen how the .NET Framework defines a Common Type System that spans all .NET programming languages. We've investigated the use of primitive types, classes, structures, enumerations, interfaces, and delegates in C# applications.

  • All primitive types (except String and Object) map to predefined value types in the .NET Framework class library. For example, if we declare an int variable in our C# code, the compiler maps this to System.Int32. This in turn translates into the int32 type in Microsoft Intermediate Language (MSIL) code.

  • Classes represent reference types. When we create a class object, it is placed on the Common Language Runtime's managed heap. Class objects exhibit copy-by-reference semantics. When a class object is no longer referenced, the object becomes available for garbage collection.

  • Structures represent value types. Value instances can be stored on the heap, or within managed objects. Value instances exhibit copy-by-value semantics. When a value instance goes out of scope, it is popped off the stack and deleted. Value instances are not subjected to garbage collection.

  • Enumerations are integral data types that have a restricted set of allowable values. In the .NET Framework, enumerations are value types.

  • Delegates represent pointers to methods. We can create a delegate to specify which method we want to invoke, and then invoke the method when we are ready. Delegates form the basis of the event mechanism in the .NET Framework.

  • Interfaces specify a contractual agreement that we can implement in other classes and structures. Interfaces enable us to decouple the what from the how in our design.

Now that we've seen how to define types in C#, we'll investigate how to design and implement these types correctly and effectively in the following chapters.




C# Class Design Handbook(c) Coding Effective Classes
C# Class Design Handbook: Coding Effective Classes
ISBN: 1590592573
EAN: 2147483647
Year: N/A
Pages: 90

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