Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
86
Chapter 3
CHAPTER 3
Classes and Structures
3.0 Introduction
Structures, like any other value type, implicitly inherit from System.ValueType. At
first glance, a structure is similar to a class but is actually very different. Knowing
when to use a structure over a class will help tremendously when designing an appli-
cation. Using a structure incorrectly can result in inefficient and hard-to-modify
code.
Structures have two performance advantages over reference types. First, if a struc-
ture is allocated on the stack (i.e., it is not contained within a reference type), access
to the structure and its data is somewhat faster than access to a reference type on the
heap. Reference type objects must follow their reference onto the heap in order to get
at their data. However, this performance advantage pales in comparison to the sec-
ond performance advantage of structures: namely, that cleaning up the memory allo-
cated to a structure on the stack requires a simple change of the address to which the
stack pointer points, which is done at the return of a method call. This call is
extremely fast compared to allowing the garbage collector to automatically clean up
reference types for you in the managed heap; however, the cost of the garbage collec-
tor is deferred so that it’s not immediately ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata