using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Example34
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] G_str_array = new string[] //定义数组
{
"C#范例宝典",
"C#编程宝典",
"C#视频学",
"C#项目开发全程实录",
"C#项目开发实例自学手册",
"C#编程词典",
"C#实战宝典",
"C#经验技巧宝典",
"C#入门模式",
};
private void button1_Click(object sender, EventArgs e)
{
int i = 0; //定义计数器
label1: //定义标签
if (G_str_array[i].Contains(textBox1.Text)) //判断是否 找到 图书
{
listBox1.SelectedIndex = i; //找到 并 选中
MessageBox.Show(textBox1.Text + "书已经找到!", "提示");
return;
}
i++;
if (i < G_str_array.Length) goto label1; //条件满足跳回到 标签
MessageBox.Show(textBox1.Text + "书没有找到!", "提示");
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.AddRange(G_str_array);
}
}
// 建议 大家 尽量少用 goto 语句 太过于灵活 或多或少地会干扰程序的执行逻辑。
}