C#语句大杂烩 看到什么写什么

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(..);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值