亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有什么好的方式可以寫引用參數的委托?

有沒有什么好的方式可以寫引用參數的委托?

C#
尚方寶劍之說 2023-02-17 17:13:58
如果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);

}
}
}
}


查看完整回答
反對 回復 2023-02-20
  • 1 回答
  • 0 關注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號