本文介绍了员工姓名和电话没有信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用C#编写没有数据库。 First Textbox有名字,第二个姓氏和第三个电话号码。
Button1保存内存中3个文本框的信息,当我按下button2时,我会看到列表框中的信息
我在下面写的时候会收到NullReferencesException错误
我试过的:
I want to write with C# without database. First Textbox has got name,second surname and third tel no.
Button1 keeps information from 3 textboxes in memory and when I press button2 I will see the information in the listbox
I get NullReferencesException error when I write below
What I have tried:
class Class1
{
public string[] information;
public int counter=1;
public string[] solution(string name, string surname, string telno)
{
information = new string[counter];
for (int i = 0; i < information.Length; i++)
{
information[i] += name + surname + telno;
counter++;
}
return information;
}
public string[] show()
{
string[] information= new string[counter];
for (int i = 0; i < information.Length; i++)
{
information[i] += information[i].ToString();
counter++;
}
return information;
}
}
private void button1_Click(object sender, EventArgs e)
{
Class1 yeni = new Class1();
string[] dizi = yeni.solution(textBox1.Text, textBox2.Text, textBox3.Text);
string metin = "";
for (int i = 0; i < dizi.Length; i++)
metin += dizi[i];
}
private void button2_Click(object sender, EventArgs e)
{
Class1 yeni = new Class1();
listBox1.Items.Add(yeni.show());
}
推荐答案
Class1 yeni;
private void button1_Click(object sender, EventArgs e)
{
yeni = new Class1();
string[] dizi = yeni.solution(textBox1.Text, textBox2.Text, textBox3.Text);
string metin = "";
for (int i = 0; i < dizi.Length; i++)
metin += dizi[i];
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(yeni.show());
}
这篇关于员工姓名和电话没有信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!