反射调用函数带func委托参数的问题

yoke_wolf 2014-09-12 05:32:25
class ClsTest
{
public void Test<TFirst, TSecond, TReturn>(Func<TFirst, TSecond, TReturn> map)
{
//....
}
}

public static void Test_Test()
{
ClsTest test = new ClsTest();

// call 1
test.Test<int, int, int>(
(a, b)=>{return a + b;}
);

// call 2
MethodInfo methodTest = test.GetType().GetMethod("Test").MakeGenericMethod(typeof (int), typeof (int), typeof(int));
ArrayList plist = new ArrayList();
plist.Add(?); // 这里
methodTest.Invoke(test, plist.ToArray());
}

请问问号处要怎么写 call 2 部分代码才能实现 call 1 相同功能
...全文
372 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2014-09-13
  • 打赏
  • 举报
回复
plist.Add(new Func<int, int, int>((x, y) => x + y));
Forty2 2014-09-13
  • 打赏
  • 举报
回复

plist.Add((Func<int, int, int>)((a, b) => { return a + b; })); // 这里
漫天雪飞 2014-09-13
  • 打赏
  • 举报
回复
引用 2 楼 Forty2 的回复:

plist.Add((Func<int, int, int>)((a, b) => { return a + b; })); // 这里
+1
Saleayas 2014-09-12
  • 打赏
  • 举报
回复
methodTest.MakeGenericMethod(new Type[]{int, int, int }).Invoke(new Func<int, int, int >(...))

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧