How to pass in a method name of a particular class as a parameter of another method
<p>I'm trying to write a C# method that generates threads by passing in an object and running one of its methods.</p>

<p>Here is an oversimplified example:</p>

<pre><code>class ThreadData {
    private JObject jsonObj;
    private int start;
    private int end;
    public ThreadData(JObject jsonObj, int start, int end) {
        this.jsonObj= jsonObj;
        this.start = start;
        this.end = end;
    }
    public void Calculate() {
        for (int i = start; i &lt; end; i++) {
            // do stuff
        }
    }
    public void Produce() {
        for (int i = start; i &lt; end; i++) {
            // do other stuff
        }
    }
}

class Program {
    static void Main(string[] args) {
        JObject jsonObj= SomeRestAPICall();
        RunInThreads(5, jsonObj, Calculate);
        RunInThreads(5, jsonObj, Produce);
    }

    // ...
}
</code></pre>

<p>The json object has n number of items. The RunInThreads method's goal is to generate X number of threads, divide up the jsonObj into equal X chunks, and have each thread run on each chunk. I pass into the method the number of threads, the json object as well as a method to run ThreadData class.</p>

<pre><code>private static void RunInThreads(int numOfThreads, JObject object, type functionToRun) {
    int chunks = object.Count() / numOfThreads;
    List&lt;Thread&gt; threads = new List&lt;Thread&gt;();
    for (int i = 1; i &lt;= numOfThreads; i++) {
        int start = (i - 1) * chunks;
        int end = i == numOfThreads? object.Count() : start + chunks;

        ThreadData threadData = new ThreadData(object, start, end);
        Thread thread = new Thread(new ThreadStart(threadData.&lt;FUNCTION&gt;));
        thread.Start();
        threads.Add(thread);
    }
    foreach (Thread t in threads) { t.Join(); }
}
</code></pre>

<p>I can't quite figure out how to pass in the function name as a parameter. Would I use a delegate? If I was using two separate methods I would put in the custom method name in each one. For instance, for the Calculate() method it would be as such:</p>

<pre><code>private static void CalculateInThreads(int numOfThreads, JObject object) {
    int chunks = object.Count() / numOfThreads;
    List&lt;Thread&gt; threads = new List&lt;Thread&gt;();
    for (int i = 1; i &lt;= numOfThreads; i++) {
        int start = (i - 1) * chunks;
        int end = i == numOfThreads? object.Count() : start + chunks;

        ThreadData threadData = new ThreadData(object);
        Thread thread = new Thread(new ThreadStart(threadData.functionToRun));
        thread.Start();
        threads.Add(thread);
    }
    foreach (Thread t in threads) { t.Join(); }
}
</code></pre>