-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