This is a C# library for common operating extensions.i.e:convert int to string、convert string to bool,etc.
这是一个.net公共类库,提供了各种常用操作,如:常用类型变量之间互转等
DotNetFool is available as NuGet Package. Type the following command into NuGet Package Manager Console window to install it:
Install-Package DotNetFool
- System.Configuration.ConfigurationManager:
The tool Cfg depends on it.
- System.Drawing.Common:
The tool ProcessImage depends on it.
- bool convert to int
var b = true;
Console.WriteLine(b.GetInt());
var b2 = false;
Console.WriteLine(b2.GetInt());
output:
1
0
- string convert to int
var s = "123.222";
Console.WriteLine(s.GetInt());
var s2 = "thankyou";
Console.WriteLine(s2.GetInt());
var s3 = "1233";
Console.WriteLine(s3.GetInt());
output:
0
0
123
- object convert to string if object is null,the default method ToString ,will throw exception,broke the program,but GetString will return string empty,is friendly.
var i = 0;
Console.WriteLine(i.GetString());
var b = false;
Console.WriteLine(b.GetString());
var f = 0.5f;
Console.WriteLine(f.GetString());
var d = 0.58989898m;
Console.WriteLine(d.GetString());
output:
0
False
0.5
0.58989898
- DateTime convert to string DateTime convert to string,if datetime is null,return string empty. format ie:yyyy-MM-dd
DateTime? d = DateTime.Now;
Console.WriteLine(d.GetString("yyyy-MM-dd"));
output:
2021-07-23