如果Action托管的函數參數有引用參數, 請問怎么寫?麻煩熟悉的朋友指點下謝謝void testinter(ref int);Aciont<ref int> a = testinter;//這句是會報錯的請問怎么寫好點是不是Action不能寫引用參數, 不想自己定義 delegate 類型
1 回答

慕田峪4524236
TA貢獻1875條經驗 獲得超5個贊
只能這么玩,現有的不支持ref
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
var w = new Work
{
OnNotify = Run
};
w.Do();
Console.Read();
}
private static void Run(ref int i)
{
i += 1;
Console.Write(i);
}
}
public delegate void RefAction<T1>(ref T1 arg1);
public class Work
{
public RefAction<int> OnNotify;
public void Do()
{
var j = 0;
for (var i = 0; i < 10; i++)
{
j += 1;
if (OnNotify != null)
{
OnNotify(ref j);
}
}
}
}
}
- 1 回答
- 0 關注
- 89 瀏覽
添加回答
舉報
0/150
提交
取消