8

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

jrouquie
  • 4,315
  • 4
  • 27
  • 43
RCIX
  • 38,647
  • 50
  • 150
  • 207

3 Answers3

14

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)
Gabe Moothart
  • 31,211
  • 14
  • 77
  • 99
4

Will the Action<T> delegate work for you?

Action<T>

Jon Sagara
  • 1,122
  • 2
  • 11
  • 16
3

You may want:

Action<T> a = (t) => // your code here...
jasonh
  • 29,297
  • 11
  • 59
  • 61