基于视频讲解的GOTO语句完整源代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] person_array = new string[]
{
"杨丞琳",
"刘亦菲",
"刘诗诗",
"刘孜",
"孙菲菲",
"熊乃瑾",
"谢娜",
"景甜",
"柳岩",
"林志玲",
"弦子",
"温岚",
"后弦",
"韩雪",
"王珞丹",
"黄圣依",
"范冰冰",
"李冰冰",
"白冰",
"韩庚",
"李小璐",
"林熙蕾",
"阿朵",
"曾黎",
"林心如",
"李小冉",
"赵薇",
"黎姿",
"周杰伦",
"蔡依林",
"陈怡蓉",
"刘芸",
"胡兵",
"胡歌",
"王子",
"炎亚纶",
"汪东城",
"唐禹哲",
"巩俐",
"章子怡",
"李宇春",
"周笔畅",
"叶一茜",
"张卫健",
"蔡少芬",
"谢霆锋",
"李念",
"熊黛林",
"舒淇",
"王力宏",
"苏有朋",
"林志颖",
"王心凌",
"张杰",
"张婧",
"吴君如",
"汤唯",
"梁朝伟",
"刘德华",
"刘嘉玲",
"李嘉欣",
"萧蔷",
"陶虹",
"蒋勤勤",
"董璇",
"安以轩",
"王艳王",
"刘涛",
"王媛可",
"梁洛施",
"梁咏琪",
"梁静茹",
"唐宁",
"杨怡",
"许绍洋",
"邓超",
"孙俪",
"孙莉",
"黄磊",
"张小斐",
"徐静蕾",
"张曼玉",
"张静初",
"张靓颖",
"张含韵",
"张少华",
"张柏芝",
"张歆艺",
"张馨予",
"张小斐",
"张钧甯",
"张茜",
"张庭"
};
private void button1_Click(object sender, EventArgs e)
{
int i=0;
la1:
if(person_array[i].Contains(textBox1.Text))
{
listBox1.SelectedIndex = i;
MessageBox.Show(textBox1.Text +"已经找到!","提示信息");
}
i++;
if(i<person_array.Length)
{
goto la1;
}
MessageBox.Show(textBox1.Text + "没有找到!", "提示信息");
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.AddRange(person_array);
}
}
}
结语:喜欢的请关注收藏!