-3

I want to do something like... So where there is a list of function delegates and access the 0 index, invoke it and return the value.

public static bool methodOne()
{
   return true;
}

var methods_list = new List<Func<Delegate>>();
methods_list.Add( () => methodOne() );

// print true
Console.WriteLine(methods_list[0].Invoke());
bob toss
  • 15
  • 4

1 Answers1

1

You need to return a Func<T>, so it returns T:

void Main()
{
    var methods_list = new List<Func<bool>>();
    methods_list.Add(() => methodOne());

    // prints true
    Console.WriteLine(methods_list[0].Invoke());
}

public static bool methodOne()
{
    return true;
}
Peter Bons
  • 26,826
  • 4
  • 50
  • 74