0
class worker
{
    public Func<int> func1 = ()=>{ return 1; };
    public int func2()
    {
        return 2;
    }
}

static void Main(string[] args)
    {
        worker w = new worker();
        int i = w.func1.Invoke();
        int j = w.func2();
        Console.WriteLine("{0}, {1}", i, j);
    }

What is exactly the difference between these two calls:

  • Func<> and
  • func()?

When should I use Func<>?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
GeorgeCN
  • 9
  • 1
  • You don't need to do `int i = w.func1.Invoke();` - just do `int i = w.func1();` – Matthew Watson Sep 15 '15 at 13:06
  • 4
    A Func is a delegate. Go read up on what delegates are. –  Sep 15 '15 at 13:06
  • OK thanks everyone. So I'm going to read about delegates. Thx again. – GeorgeCN Sep 15 '15 at 13:14
  • I do not really see this as a duplicate. He isn't asking what a delegate is, but rather what the difference is between the two tools, **Func<>** and **func()**. I would answer, but I do not know either. –  Sep 15 '15 at 13:14

0 Answers0