11.07.2015 Views

Beginning C# 2008-from Novice-to-professional - A2Z Dotnet

Beginning C# 2008-from Novice-to-professional - A2Z Dotnet

Beginning C# 2008-from Novice-to-professional - A2Z Dotnet

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

60CHAPTER 3 ■ LEARNING ABOUT STRING MANIPULATIONSFigure 3-5. GetType() retrieves the metadata associated with an object.Figure 3-6. ToString() converts the contents of the type in<strong>to</strong> a string.The four basic methods can be called on every variable that you declare. You will useToString() when debugging or inspecting the state of an object instance during runtime.ToString() returns a human-readable string that contains the state of the object instance.You might use the GetType() method occasionally, but your IDE and other <strong>to</strong>ols will use itall the time. Using GetType(), you have the ability <strong>to</strong> figure out the capabilities of a variableduring the execution of a program. In technical terms, GetType() returns the formal metadatadescription of the type.From reading the description of Equals() and GetHashCode(), you would get the impressionthat these two functions serve the same purpose. However, this is not the case.Let’s say you’re moving and you’ve packed two boxes containing kitchen items. Both boxescontain five red dishes, three silver forks, two copper knives, and two wineglasses. If you comparethe boxes, both Equals() and GetHashCode() will return equality, indicating the boxes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!