1 Double toString保留小数点方法
int i = 25;
string str0 = i.ToString("f"); //25.00
string str1 = i.ToString("f1"); //25.0
string str2 = i.ToString("f2"); //25.00
string str3 = i.ToString("f3"); //25.000
string str4 = i.ToString("f4"); //25.0000
其他方式:
int i = 111125;
string str0 = i.ToString("n"); //111,125.00
string str1 = i.ToString("n1"); //111,125.0
string str2 = i.ToString("n2"); //111,125.00
string str3 = i.ToString("n3"); //111,125.000
string str4 = i.ToString("n4"); //111,125.0000
2 delegate类
命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)
委托(Delegate)类是一种数据结构,通过它可引用静态方法或引用类实例及该类的实例方法。 以往的界面编程中我们应该都接触过各种类型的事件驱动(event driven)的处理模式,在这种模式里,我们定义相应事件触发的函数。
例如:Button1 的 Click事件,我们可以编写Button1_Click 或 Btn1Clicked等函数来做相应的驱动处理。而事件与驱动函数的对应关系就是通过委托(Delegate)类来关联的。其实委托(Delegate)类这种数据结构有些类似于之前C/C++中的函数指针。
Delegate类一个简单应用:
- 定义一个Delegate函数数据结构
- 定义Delegate将引用的静态方法或引用类实例及该类的实例方法
- Delegate数据变量指向实例方法
通过Delegate数据变量执行实例方法
using System;
namespace MySample
{
class TestClass
{
//1.定义一个Delegate函数数据结构
public delegate void GoDelegate();
[STAThread]
static void Main(string[] args)
{
//3.Delegate数据变量指向实例方法
GoDelegate goDelegate = new GoDelegate( MyDelegateFunc);
//4.通过Delegate数据变量执行实例方法
goDelegate();
return;
}
//2.定义Delegate将引用的静态方法或引用类实例及该类的实例方法
public static void MyDelegateFunc()
{
Console.WriteLine("delegate function...");
}
}
}
3 线程
- 创建线程的第一种方法,无返回值:
var task = new Task(..);