Welcome to MSDN Blogs Sign in | Join | Help

The SLAR on System.Convert [Brad Abrams]

It is been a while sense I posted in the series sharing some of the information in the .NET Framework Standard Library Annotated Reference Vol 1.  Given today is BCL blog day, I thought I would kick it off by adding a couple of annotations from the System.Convert class.  Enjoy!

 

Brad Abrams:

Early in the design of the BCL we went back and forth trying to decide how we wanted conversions to be supported in the library. Initially we wanted to distribute

them as instance methods in each class:

int i = 10;

double d = Int32.ToDouble(i);

This design has the advantage of being more easily discoverable as it does not require an intermediate object. Later, we tried a different design that had a single object with all the conversions, so that the same conversion would be:

int i = 10;

double d = Convert.ToDouble(i);

We liked this approach because if the developer needs to change the type of the i variable to a long she would only have to change the declaration, not every usage:

long i = 10;

double d = Convert.ToDouble(i);

 

Anders Hejlsberg:

In the early days of .NET we had two types that could be used to represent dynamically typed values: System.Object and System.Variant. System.Variant was basically a managed wrapper for OLE Automation variants. Having two ways of doing what amounts to the same thing caused tremendous confusion in the libraries. Some APIs would use Object, others would use Variant.

Some even tried to support both, which introduced lots of ambiguities. We finally made the hard call to get rid of Variant. In retrospect, this was clearly the right decision. We can now say that “every piece of data in .NET is an object,” which brings about tremendous conceptual simplification. The types of operations that were traditionally provided by OLE Automation’s variant support, such VarChangeType() that converts a variant from one type to

another, is now provided by the Convert class and the IConvertible interface.

Published Tuesday, March 15, 2005 12:19 PM by BCLTeam
Filed under:

Comments

Thursday, March 17, 2005 3:16 PM by David Boschmans' Weblog

# Tips

Tips
Monday, March 21, 2005 12:37 PM by Ido Samuelson

# Tips

Tips
Monday, March 28, 2005 2:37 AM by Claudio Brotto

# System.Variant

Saturday, January 27, 2007 5:26 AM by Claudio Brotto

# System.Variant

In un'annotazione a proposito di System.Convert, riportata in questo post di Brad Abrams dal volume .NET

# BCL Team Blog The SLAR on System Convert Brad Abrams | debt settlement program

New Comments to this post are disabled
 
Page view tracker