All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#2.0基本语法一_[Asp.Net教程]
Windows下Apache+Tomcat+MySQL+jsp+php的服务器整合配置经验总结_[PHP教程]
Sql,server,CLR自定义类型存储对象_[SQL,Server教程]
C#中的GDI+概述
关于HTTP及XMLHTTP状态代码一览_[XML教程]
PHP入门:动态网页制作技术PHP的常量类型_[PHP教程]
SQL,Server开发的二十一条军规_[SQL,Server教程]
ASP.NET中Multi-ListBox控件编程详解_[Asp.Net教程]
PHP和MySQL分页显示实例分析_php资料_编程技术
网页制作知识:XHTML 和 DOCTYPE 切换_[Html教程]
Reading number is top 10 pictures
机器人也有性生活吗?
Summer is most suitable for young people to travel in China3
Valentine's day comes, send some cartoon
Born After 90 Beijing sports university campus flower photos5
身材野火台灣美女1
Sora aoi on twitter3
The money of more than 100 countries and regions13
Soldier saw beauty after the reaction
In the world the most mysterious 21 place landscape4
The little girl with long hair2
Download software ranking
Unix video tutorial18
Wild things 2
Popkart Cracked versions Mobile phone games
塘西风月痕
美女写真2
matrix1
Unix video tutorial3
星际争霸1.08硬盘免安装版
天龙八部最新服务端
美女写真3
qq published in(发表于) 2014/7/11 9:16:57 Edit(编辑)
C#中goto语句的使用方法

C#中goto语句的使用方法

C#中goto语句的使用方法

C#中goto语句的使用方法

goto语句属于无条件的跳转语句,因为C#允许在代码行加上标签,这样就可以用goto语句直接跳转到这些代码行上。该语句有其优缺点,优点在于可以方便地控制何时去执行指定代码;主要缺点在于过多地使用这个语句将很难读懂代码段。

示例

goto语句的使用

通过使用goto语句跳出嵌套循环完成数字的查找,程序代码如下:

using System;

public class GotoTest1

{

static void Main()

{

int x = 200, y = 4;

int count = 0;

string[,] array = new string[x, y];

for (int i = 0; i < x; i++)

for (int j = 0; j < y; j++)

array[i, j] = (++count).ToString();

Console.Write("输出结果为:n输入查找的数字:");

string myNumber = Console.ReadLine();

for (int i = 0; i < x; i++)

{

for (int j = 0; j < y; j++)

{

if (array[i, j].Equals(myNumber))

{

goto Found;

}

}

}

// http://www.isstudy.com

Console.WriteLine("数字{0} 无法找到.", myNumber);

goto Finish;

Found:

Console.WriteLine("数字{0} 存在.", myNumber);

Finish:

Console.WriteLine("结束查找.");

Console.Read();

}

}


键运行程序,运行结果如图1所示。



图1 goto语句

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Text;

namespace _3_13

{

class Program

{

static void Main()

{

int x = 200, y = 4;

int count = 0;

string[,] array = new string[x, y];

for (int i = 0; i < x; i++)

for (int j = 0; j < y; j++)

array[i, j] = (++count).ToString();

Console.Write("输出结果为:n输入查找的数字:");

string myNumber = Console.ReadLine();

for (int i = 0; i < x; i++)

{

for (int j = 0; j < y; j++)

{

if (array[i, j].Equals(myNumber))

{

goto Found;

}

}

}

Console.WriteLine("数字{0} 无法找到.", myNumber);

// http://www.isstudy.com

goto Finish;

Found:

Console.WriteLine("数字{0} 存在.", myNumber);

Finish:

Console.WriteLine("结束查找.");

Console.Read();

}

}

}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.