Func not returning anything?

2019-06-17 04:46发布

问题:

This may sound like a bit of a dumb question but how do I make a Func<> variable that doesn't return anything?

回答1:

You can use Action<T> for a delegate that takes a variable and returns void.

But note that you can also just declare your own delegate types if you want to. Action<T>, for example, is just

public delegate void Action<T>(T obj)


回答2:

Will the Action<T> delegate work for you?

Action<T>



回答3:

You may want:

Action<T> a = (t) => // your code here...


标签: c# lambda