基本上我想创建一个方法,该方法可以返回关于方法中当前发生的内容的字符串消息 例如:
//remove the first element of the tuple thereby decreasing its size by one
myTuple.pop_front()
//add addThis as the first element of the tuple thereby increasing its size by one
myTuple.push_front(addThis)
使用它时我想的就像这样
public MainMethod()
{
//Execute One
//Execute Two
//Execute Three
}
输出将是
something = delegate (string message) {console.writeline("{0}",message)};
这可以使用delegate或lambda吗?如果是的话,我可以问一个关于如何正确实现这个问题的例子吗?如果没有,请帮助我替代。
由于
答案 0 :(得分:2)
使用Func
和Action
。他们使与代表的互动变得更加容易。 Func
具有返回值,Action
不具有:
public MainMethod()
{
Action<string> writerAction = (message) => Console.WriteLine(message);
writerAction("Execute One");
writerAction("Execute Two");
writerAction("Execute Three");
}