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.
100
|
Chapter 3: Classes and Structures
The following code:
Console.WriteLine("Line.Parse(\"(12,2)(0,45)\") = " + Line.Parse("(12,2)(0,45)"));
Console.WriteLine("Line.Parse(\"(0,0)(0,0)\") = " + Line.Parse("(0,0)(0,0)"));
produces this output:
Line.Parse("(12,2)(0,45)") = (12,2) (0,45)
Line.Parse("(0,0)(0,0)") = (0,0) (0,0)
When implementing a Parse method on your own types, you need to
consider the situation in which invalid data is passed to this method.
When this happens, an
ArgumentException should be thrown. When a
null is passed in, you should instead throw an ArgumentNullException.
See Also
See the “Parse Method” topic and the parse sample under the “.NET Samples—How
To: Base Data Types” topic in the MSDN documentation.
3.4 Implementing Polymorphism
with Abstract Base Classes
Problem
You need to build several classes that share many common traits. These classes may
share common properties, methods, events, delegates, and even indexers; however,
the implementation of these may be different for each class. These classes should not
only share common code but also be polymorphic in nature. That is to say, code that
uses an object of the base class should be able to use an object of any of these derived
classes in the same manner.
Solution
Use an abstract base class to create polymorphic code. ...
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