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.
356
|
Chapter 6: Iterators and Partial Types
See Also
See the “Iterators,” “yield,” “IEnumerator Interface,” and “IEnumerable Interface”
topics in the MSDN documentation.
6.10 Organizing Your Interface Implementations
Problem
You have a class that implements an interface with many methods. These methods
support only the interface functionality and don’t necessarily relate well to the other
code in your class. You would like to keep the interface implementation code sepa-
rate from the main class code.
Solution
Use partial classes to separate the interface implementation code into a separate file.
For example, you have a class called
TriValue that takes three decimal values and
performs some operations on them, like getting the average, the sum, and the prod-
uct. This code is currently in a file called TriValue.cs, which contains:
public partial class TriValue
{
decimal first;
decimal second;
decimal third;
public TriValue(decimal val1, decimal val2,decimal val3)
{
this.first = val1;
this.second = val2;
this.third = val3;
}
public TypeCode GetTypeCode( )
{
return TypeCode.Object;
}
public decimal GetAverage( )
{
return (GetSum( ) / 3);
}
public decimal GetSum( )
{
return first + second + third;
}
public decimal GetProduct( )
{
This is the Title of the Book, eMatter Edition
Copyright © 2007 ...
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

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata