菜鸟初学C#~程序出现问题求解答~谢
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static int iCounter = 0;
string[,] sPhoneNumberList;
private void button1_Click(object sender, EventArgs e)
{
sPhoneNumberList = new string[4, 2];
if (textBox1.Text != "" && textBox2.Text != "")
{
sPhoneNumberList[iCounter, 0] = textBox1.Text;
sPhoneNumberList[iCounter, 1] = textBox2.Text;
MessageBox.Show("输入成功");
}
else
MessageBox.Show("请输入公司名称以及电话号码");
iCounter++;
textBox1.Clear();
textBox1.Focus();
textBox2.Clear();
if (iCounter >= 4)
label3.Text += ("电话簿已满");
else
label3.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
string sSerarhName;
if (textBox1.Text != "")
{
for (iCounter = 0; iCounter <= 4; iCounter++)
{
sSerarhName = textBox1.Text;
if (sPhoneNumberList[iCounter, 0] == sSerarhName)
textBox2.Text = sPhoneNumberList[iCounter, 1];
}
if (iCounter >= 4)
label3.Text = "不存在所查询的公司,请重新输入";
}
else
MessageBox.Show("请输入公司名称");
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
刚开始学,加红的地方是提示出错的地方,个人分析原因是sPhoneNumberList是在button1_Click这个里定义并且赋值的,算局部变量,所以其值并没有传递在button2_Click中的sPhoneNumberList,不知道分析的对不对,还请高人指教;
如果是这个原因,请问应该如何改正,以前完全没接触过C#或者是其他面向对象的语言,实在是不会处理,麻烦各位了,万分感谢