Здравейте!
Във Visual Studio имам създадено приложение на Windows Forms App (Visual Basic).
Искам това приложение да го създам и на Windows Forms App (C#).
Как да преобразувам кода? Възможно ли е?
private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text = "Доабавяне на запис")
{
bool f = false; // Декларацията и задаване на стойност става вече на един ред
for (int i = 0; i < ListBox1.Items.Count; i++) // Еквивалентно на For ... To ..
{
if (ListBox1.Items[i] == txtInput.Text)
{
f = true;
break;
}
}
if (!f)
{
ListBox1.Items.Add(textInput.Text);
}
else
{
MessageBox.Show("Елементът се дублира!", "Грешка при добавяне", 0, MessageBoxIcon.Error);
}
txtInput.Text = "";
txtInput.Focus();
if (ListBox1.Items.Count > 0)
{
btnClear.Enabled = true;
}
}
else
{
ListBox1.Items[ListBox1.SelectedIndex] = txtInput.Text;
txtInput.Text = "";
ListBox1.SelectedIndex = -1;
btnAdd.Text = "Добавяне на запис";
}
}
Регистрирани потребители: Google Adsense [Bot], Google [Bot]