泛型委托Action中类型参数应该怎么传递?

sordar 2016-09-01 03:53:59
public class testclass
{
public void testa(Func<String,String> action)
{

Console.WriteLine(action("what?"));
}

public void testall()
{
testa(tc =>
{
return tc;
});

testb<string>(tc =>
{
Console.WriteLine(tc);
});
}

public void testb<T>(Action<T> action)
{
//这里怎么调用action以传入一个string?如action("abc")
}

}
...全文
561 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sordar 2016-09-01
  • 打赏
  • 举报
回复
Thanks, I just write as following: public void testb<T>(Func<T, T> action, T testValue) { action(testValue); } public void testall() { testa(tc => { return tc; }); testb<string>(tc => { return tc; }, "abc"); }
Forty2 2016-09-01
  • 打赏
  • 举报
回复
public void testb<T>(Action<T> action, T arg)

111,129

社区成员

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

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

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