C#里准确的说法应该叫委托,委托的方法有多种,下面介绍Action<T>,可以做为一个函数参数递。

//引用

using System;

    void Start () {

          TestMain (test);

    }

void TestMain(Action<int> tt){
       Debug.Log("testMain");
//如果工作完成
       tt (0);
}
void test(int x){
        Debug.Log("test");
}

 也就是说,封装的方法必须具有一个通过值传递给它的参数,并且不能返回值。 也就是说Action<T>必须与test(T)对应,至少有一个参数,test必须为void。

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2021-12-24
  • 2021-08-14
  • 2022-02-26
  • 2021-06-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-03
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案