1

私のプログラムでは、関数をパラメーターとして取得し、別の関数内から呼び出すことを想定しています。それはできますか?
ありがとうございました

4

5 に答える 5

0

または、ラムダ式を使用できます。デリゲートはそのままですが、コーディングはより高速です。

private static void Main(string[] args)
{
    NoReturnValue((i) =>
        {
            // work here...
            Console.WriteLine(i);
        });
    var value = ReturnSometing((i) =>
        {
            // work here...
            return i > 0;
        });
}

private static void NoReturnValue(Action<int> foo)
{
    // work here to determind input to foo
    foo(0);
}

private static T ReturnSometing<T>(Func<int, T> foo)
{
    // work here to determind input to foo
    return foo(0);
}
于 2011-08-15T18:39:06.900 に答える