有两个文本框,例如第一个文本框的用户输入 " emre",当用户输入第二个文本框" e",好的...... 但其他人,程序将在messagebox中出错。 我的问题是:如果用户输入不同的字符, 程序爆炸:)我想我错了:textbox2.text [i] == a [i]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string a;
string final = "";
int i = 0;
string b;
private void textBox1_TextChanged(object sender, EventArgs e)
{
a = textBox1.Text;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text[i] == a[i])
{
final += textBox2.Text[i];
textBox2.Text = final;
i++;
}
else
{
textBox2.Text = final;
MessageBox.Show("Lütfen aynı ismi girin!");
}
}
}
}