CHAPTER 32

image

Making Friends with the .NET Framework

The information in the preceding chapters is sufficient for writing objects that will function in the .NET Runtime, but those objects may not work as expected when used in collections or when debugged. This chapter details a few ways to improve this situation.

ToString( )

Overriding the ToString() function defined in the object class gives a nice representation of the values in an object. If this isn’t done, object.ToString() will merely return the name of the class, which will make debugging more difficult.

Here’s an example of the default behavior:

using System;public class Employee{    public ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.