
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Converting a String Representation of an Object into an Actual Object
|
99
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 Parse method is used to reconstruct one data type—in this case, a String—into
the data type containing that
Parse method. For example, if the string "123" were
passed into the
int.Parse method, the numeric data type 123 would be extracted and
then returned. Many other types in the FCL use a
Parse method to reconstruct an
object of its own type from another data type, such as a
string. Note that you are
not limited as far as the type ...