This project is read-only.

static DataConvert class

May 14, 2010 at 4:12 AM
Edited May 14, 2010 at 12:35 PM

What is DataConvert?

DataConvert is a static class (similiar to the Convert class found in the .NET framework) used to convert data from one type to a different type.  What distinguishes itself from the Convert is it never throws exception in an event of conversion failure.  Rather, the underlying type's default value or a user specified value will be returned instead.

When to use DataConvert?

 I used this static class on all of my projects to (1) convert data, (2) read data from database, or (3) read user input via text box.  It is much simplier than writing the code using the TryParse() approach.

int a;
if (!int.TryParse(textBox1.Text, out a))
{
    a = 0;
}
return a;

The above block of code is similar using the DataConvert class

return DataConvert.ToInt32(textBox1.Text, 0)

...