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.
92
|
Chapter 3: Classes and Structures
public string ToString(string format, IFormatProvider formatProvider)
{
StringBuilder compositeStr = new StringBuilder("");
if ((format != null) && (format.ToUpper( ).Equals("V")))
{
double direction = this.GetDirectionInRadians( );
double magnitude = this.GetMagnitude( );
string retStringD = direction.ToString("G5", formatProvider);
string retStringM = magnitude.ToString("G5", formatProvider);
compositeStr.Append("magnitude = ").Append(retStringM).Append
("\tDirection = ").Append(retStringD);
}
else
{
string retStringX1 = this.x1.ToString(format, formatProvider);
string retStringY1 = this.y1.ToString(format, formatProvider);
string retStringX2 = this.x2.ToString(format, formatProvider);
string retStringY2 = this.y2.ToString(format, formatProvider);
compositeStr.Append("(").Append(retStringX1).Append(",").Append
(retStringY1).Append(")(").Append(retStringX2).Append
(",").Append(retStringY2).Append(")");
}
return (compositeStr.ToString( ));
}
}
Discussion
The ToString method provides a convenient way to display the current contents, or
state, of a structure (this recipe works equally well for reference types). The solution
section of this recipe shows the various implementations of
ToString for both
numeric and textual data. The
Line class ...
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