I'm a bit of a novice with Reflection. I'm hoping that it's possible to do what I'd like it to. I've been working through ProjectEuler to learn the language, and I have a base class called Problem. Every individual PE problem is a separate class, i.e. Problem16. To run my calculations, I use the following code:
using System;
using Euler.Problems;
using Euler.Library;
namespace Euler
{
static class Program
{
[STAThread]
static void Main()
{
Problem prob = new Problem27();
}
}
}
I have completed 50 problems now, and I want to create a loop to run them all. My base class Problem has a method that appends to a text file the problem number, the answer, and the execution time that's called in each class's default constructor. I could manually change the function call for all 50, but as I continue to complete problems, this will end up being a lot of work.
I'd much rather do it programatically. I was hoping for this pseudocode become a reality:
for (int i = 1; i <= 50; i++)
{
string statement = "Problem prob = new Problem" + i + "();";
// Execute statement
}