The SafeConvert is a .NET library used to convert data between data types safely.
In order to use this library, your application needs the .NET Framework 3.5 or higher. If okay, you can install via two following ways:
- Via Nuget: Install-Package SafeConvert
- Via Github: git clone https://github.com/congdongdotnet/SafeConvert.git
After refering to the SafeConvert library, remember that you need to include the library by using keyword:
using SafeConvert;Convert from string "1" to byte
var b = "1".ToByte(); // Print 1Convert from string "10" to short
var s = "10".ToShort(); // Print 10Convert from string "100" to int
var n = "100".ToInt(); // Print 100Convert from string "1000" to long
var l = "1000".ToLong(); // Print 1000Convert from string "6.5" to float
var f = "6.5".ToFloat(); // Print 6.5Convert from string "6.5" to decimal
var d = "6.5".ToDecimal(); // Print 6.5Convert from string "6.5" to double
var d = "6.5".ToDouble(); // Print 6.5Convert from string "2014-12-02 11:00:00" to DateTime
var dateTime = "2014-12-02 11:00:00".ToDateTime();Convert from string "20" to int using generic
var n = "20".To<int>();Each extension methods has the default value in case of failing to parse. E.g: convert from string "abc" to int using default value
var n = "abc".ToInt(10); // Print default value 10 because of failing to parseThis library has been tested 
Copyright 2015 by CongDongDotNet - MIT License
