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.
116
|
Chapter 3: Classes and Structures
Sorted ArrayList using IComparable
Height:2 Width:1
Height:1 Width:3
Height:6 Width:1
Height:4 Width:3
Search using IComparable
found (6,1): 2
SORTEDLIST
0 : Height:1 Width:3
1 : Height:2 Width:1
2 : Height:4 Width:3
3 : Height:6 Width:1
SortedListOfSquares.Contains(2): True
SortedListOfSquares.ContainsKey(2): True
SortedListOfSquares.ContainsValue(new Square(6,1)): False
See Also
See Recipe 3.5; see the “IComparable Interface” and “IComparer Interface” topics in
the MSDN documentation.
3.7 Indirectly Overloading the +=, –=, /=,
and *= Operators
Problem
You need to control the handling of the +=, –=, /=, and *= operators within your data
type; unfortunately, these operators cannot be directly overloaded.
Solution
Overload these operators indirectly by overloading the +, , /, and * operators, as
demonstrated in Example 3-9.
Example 3-9. Overloading the +, –, /, and * operators
public class Foo
{
// Other class members...
// Overloaded binary operators
public static Foo operator +(Foo f1, Foo f2)
{
Foo result = new Foo( );
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Indirectly Overloading the +=, ...
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