I start a little with Reflection. I hope it is possible to do what I would like. I work through ProjectEuler to learn the language, and I have a base class called "Problem". Each individual PE problem is a separate class, i.e. problem 16. To do 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(); } } }
Now I have completed 50 problems, and I want to create a loop to run them. My problem with the base class has a method that adds the problem number, response, and runtime to the text file, which is called in each default constructor of the class. I could manually change the function call for all 50, but as I continue to solve problems, this will ultimately be a lot of work.
I would rather do it programmatically. I was hoping this pseudo code would become a reality:
for (int i = 1; i <= 50; i++) { string statement = "Problem prob = new Problem" + i + "();";
reflection c #
wmaynard
source share