我正在制作一个程序,每次程序检查它不是一个独特的数字时,每年会增加+1,直到它为一。我不知道为什么它不起作用,任何帮助将不胜感激。我回家后昨天工作,但今天它只是不想工作。
private void yearInput_TextChanged(object sender, EventArgs e) // Year Input Textbox \\
{
}
public bool exception;
public static int yearInputInt;
public static strng yearInputString;
private void yearInputConfirm_Click(object sender, EventArgs e) // Year Input Confirm Button \\
{
exception = false;
yearInputString = yearInput.Text;
yearInputInt = Int32.Parse(yearInputString);
if (yearInputString.Length == 2)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
if (yearInputString.Length == 3)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(2, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
}
}
}
}
if (yearInputString.Length == 3)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(2, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
if (yearInputString.Length == 4)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(3, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
}
}
}
}
if (yearInputString.Length == 4)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring (2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(3, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
if (yearInputString.Length == 5)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(3, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(3, 1) == yearInputString.Substring(4, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
}
}
}
}
if (yearInputString.Length == 5)
{
while (yearInputString.Substring(0, 1) == yearInputString.Substring(1, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(0, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(2, 1) || yearInputString.Substring(1, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(3, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(3, 1) || yearInputString.Substring(2, 1) == yearInputString.Substring(4, 1) || yearInputString.Substring(3, 1) == yearInputString.Substring(4, 1))
{
yearInputInt = yearInputInt + 1;
yearInputString = yearInputInt.ToString();
}
}
label2.Text = yearInputString;
}
当我在Visual Studio中编译时,编译过程只是崩溃并得到错误:
1>------ Build started: Project: distinctDigitsRev, Configuration: Debug Any CPU ------
1>H:\profile\desktop\C#\distinctDigitsRevamped\distinctDigitsRev\distinctDigitsRev\Form1.cs(28,23,28,28): error CS0246: The type or namespace name 'strng' could not be found (are you missing a using directive or an assembly reference?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== –
答案 0 :(得分:1)
在第8行,字符串拼写错误。
public static strng yearInputString;
该行应为:
public static string yearInputString;
答案 1 :(得分:0)
声明变量 yearInputString 。请注意,您从 string 中缺少 i 。