5
public class Foo
{
    public void DoFoo()
    {
       int x;
       var coll = TheFunc("bar", out x);
    }

    public Func<string, int, ICollection<string>> TheFunc { get; set; }
}

错误:“参数 2 不应与 'out' 关键字一起传递。”

public class Foo
{
    public void DoFoo()
    {
       int x;
       var coll = TheFunc("bar", out x);
    }

    public Func<string, out int, ICollection<string>> TheFunc { get; set; }
}

错误:“无效的变体修饰符。只能将接口和委托类型参数指定为变体。”

如何在此函数中获取 out 参数?

4

2 回答 2

8

定义一个委托类型:

public delegate ICollection<string> FooDelegate(string a, out int b);

public class Foo
{
    public void DoFoo()
    {
       int x;
       var coll = TheFunc("bar", out x);
    }

    public FooDelegate TheFunc { get; set; }
}
于 2011-07-22T20:21:01.053 回答
7

您需要制作自己的代表:

delegate ICollection<string> MyFunc(string x, out int y);
于 2011-07-22T20:20:25.190 回答