-2
如何在3秒内将此结果打印到控制台?我以前的问题是过于具体的静态方法错误,而不是优化部分....如何在3秒内写入200万条记录?
我需要能够在控制台上以3秒的特定方式打印这种阵列的组合。
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); }
}
}
您无法从静态方法引用非静态属性,请参阅http://stackoverflow.com/questions/2559527/non-static-variable-cannot-be-referenced-from-a-static-context –
[你可以访问实例变量,如果你真的想](http://stackoverflow.com/questions/3371839/is-it-possible-to-access-an-instance-variable-via-a-static-method )但我建议让n也是静态的。 – mbx
@TiesonT。你的“重复”是[标签:java],而不是[标签:c#] - 虽然在这种情况下,两者行为相似,我通常建议不要参考另一种语言的答案。 – mbx