-1

How do I print this results to the console in under 3 seconds? My previous question was too specific towards the static method error and not the optimization part....

I need to be able to print this combination of arrays in a specific manner under 3 seconds on the console.

using System;

namespace MelodiousPassword
{
    private static int _n;
    static void Main(string[] args)
    {
        _n = Convert.ToInt32(Console.ReadLine());
        string[] c = { "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z" };
        string[] v = { "a", "e", "i", "o", "u" };
        Passwords("", c, v);
        Passwords("", v, c);
    }

    static void Passwords(string w, string[] a, string[] b)
    {
        if (w.Length == _n)
            Console.WriteLine(w);
        else
            foreach

            (var l in a) { Passwords(w + l, b, a); }
    }
}
Matt
  • 135
  • 3
  • 17
  • You can't reference a non-static property from a static method, see http://stackoverflow.com/questions/2559527/non-static-variable-cannot-be-referenced-from-a-static-context – Daniel Bernsons Mar 16 '17 at 05:50
  • [You could access the instance variable if you really wanted to](http://stackoverflow.com/questions/3371839/is-it-possible-to-access-an-instance-variable-via-a-static-method) but I suggest making n also static. – mbx Mar 16 '17 at 06:38
  • 1
    @TiesonT. your "duplicate" is [tag:java], not [tag:c#] - while in this case both behave alike I generally advise against referring to an answer for another language. – mbx Mar 16 '17 at 06:40

1 Answers1

1

Since the Main method is a static method, you should also change the n variable to static. Do it like this:

internal static int n;

Other than that, it seems like you'll have another error. You're passing 4 arguments to your Passwords method which only has 3 parameters.

Hope it helps!

mindOfAi
  • 4,412
  • 2
  • 16
  • 27