Applied Microsoft .NET Framework Programming Rhode Island

Jeffrey Richter provides chapter 6, 'Common Object Operations,' from his new book, Applied Microsoft .NET Framework Programming.

Local Companies

OWV Store
401-699-6634
6 Vista Dr
East Providence, RI
ProActive Computer Services LLC
401-647-7702
128 Cucumber Hill road
Foster, RI

provided by: 
Originally published at Internet.com


The following is extracted from the book Applied Microsoft .NET Framework Programming by Jeffrey Richter (Microsoft Press, 2002, ISBN: 0-7356-1422-9). Copyright 2002, Jeffrey Richter. Reproduced by permission of Microsoft Press. All rights reserved. -----------------------------------

Common Object Operations



In this chapter, I'll describe how to properly implement the operations that all objects must exhibit. Specifically, I'll talk about object equality, identity, hash codes, and cloning.

Object Equality and Identity



The System.Object type offers a virtual method, named Equals, whose purpose is to return true if two objects have the same "value". The .NET Framework Class Library (FCL) includes many methods, such as System.Array's IndexOf method and System.Collections.ArrayList's Contains method, that internally call Equals. Because Equals is defined by Object and because every type is ultimately derived from Object, every instance of every type offers the Equals method. For types that don't explicitly override Equals, the implementation provided by Object (or the nearest base class that overrides Equals) is inherited. The following code shows how System.Object's Equals method is essentially implemented: class Object { public virtual Boolean Equals(Object obj) { // If both references point to the same // object, they must be equal. if (this == obj) return(true); // Assume that the objects are not equal. return(false); } ' } ...

Read article at Internet.com site

Featured Local Company

ProActive Computer Services LLC

401-647-7702
128 Cucumber Hill road
Foster, RI
http://www.pcsllcri.com


Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML