以下の内容はhttps://mochimoffu.hateblo.jp/entry/2020/05/21/003000より取得しました。


C#の話~戻り値を返すコールバック宣言方法~

今まで、コールバックは戻り値を返す事が無かった、もしくは、引数にコールバック関数を渡して、パラメータを渡してもらっていたのだが、
戻り値普通に受け取る方法無いのかなと思って調べたら、あったのでメモ。

docs.microsoft.com

Func<引数1, 引数n, 戻り値>
で宣言すればよい。

using System;
using UnityEngine;

public class FuncCallbackTest : MonoBehaviour
{
    private Func<string, int> ReturnIntCallback = null;
    // Start is called before the first frame update
    void Start()
    {
        Test();
    }

    private void Test()
    {
        ReturnIntCallback = ReturnIntFunction;
        int res = ReturnIntCallback("10");
        Debug.Log(res);// 10
    }

    private int ReturnIntFunction(string arg)
    {
        int res = int.Parse(arg);
        return res;
    }
}



以上の内容はhttps://mochimoffu.hateblo.jp/entry/2020/05/21/003000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14