我正在尝试通过 Windows 表单反转字符串,但由于任何原因,for
循环在我执行代码时给出异常。
System.NullReferenceException:对象引用未设置为对象的实例
Button_Click 事件
string input=textBox1.Text;
input=Convert.ToString(Console.ReadLine());
string output="";
if(textBox1.Text=="")
{
MessageBox.Show("Sorry! You have not given any input for perform action");
}
else
{
try{
for(int i=input.Length-1; i>=0; i--)
{
output= output+input[i];
}
textBox2.Text=output;
}
catch(Exception ex)
{
MessageBox.Show(""+ex);
}
}
}
虽然相同的逻辑与控制台应用程序完美配合。我知道我缺少非常基本的东西,但目前我没有想法。