我是编程新手。我正在努力编写一个小程序,但我坚持将表格从一个班级传递给班级
这是主要类:
namespace WindowsFormsApplication1
{
public partial class Insomnia : Form
{
private void button3_Click(object sender, EventArgs e)
{
int outputValue = 0;
bool isNumber = false;
isNumber = int.TryParse(textBox1.Text, out outputValue);
if (isNumber == false)
{
MessageBox.Show("Error: That's not a number!");
}
else
{
if (!listBox1.Items.Contains(textBox1.Text))
{
listBox1.Items.Add(textBox1.Text);
textBox1.Text = textBox1.Text.Remove(0);
textBox1.Focus();
}
else
{
MessageBox.Show("Present already!");
}
}
}
}
}
这是第二个类,总是打印“listBox1为空”:
public class Metodi : Insomnia
{
bool isAvailable;
public void StartListen()
{
string[] arr = new string[listBox1.Items.Count];
if (listBox1.Items.Count == 0)
{
MessageBox.Show("listBox1 is empty!");
}
else
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
arr[i] = listBox1.Items[i].ToString();
}
}
ETCETC...
你能告诉我我做错了吗?请轻松说话,因为我不熟悉编码(我也不是英文:P)
感谢!