110,502
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
int[] index = GetNextIndex(null);
StringBuilder strB = new StringBuilder();
while (index.Length < 3)
{
strB.Clear();
foreach (int charIndex in index)
{
strB.AppendFormat("{0}", (char)(charIndex+'a'));
}
strB.Append("\n");
//你要的结果
richTextBox1.Text += strB.ToString();
//获取下一组下标
index = GetNextIndex(index);
}
}
private int[] GetNextIndex(int[] curIndex)
{
List<int> indexList = new List<int>();
if (curIndex == null || curIndex.Length < 1)
{
curIndex = new int[] { -1 };
}
curIndex[0]++;
bool isAddNew = false;
for (int i = 0; i < curIndex.Length; i++)
{
if (curIndex[i] > 25)
{
curIndex[i] = 0;
if (i + 1 < curIndex.Length)
curIndex[i + 1]++;
else if (i + 1 < 25)
isAddNew = true;
}
}
indexList.AddRange(curIndex);
if (isAddNew) indexList.Add(0);
return indexList.ToArray();
}