定义一个数组int[] number =new int[] {1,2,3,4,5},使用foreach循环结构输出数组中的数据

[复制链接]
查看11 | 回复2 | 2011-8-8 16:46:23 | 显示全部楼层 |阅读模式
定义一个数组int[] number =new int[] {1,2,3,4,5},使用foreach循环结构输出数组中的数据,要求遇到3将不输出,遇到5将退出循环,我就是不知道foreach循环里怎么让他不输出3。初学者

回复

使用道具 举报

千问 | 2011-8-8 16:46:23 | 显示全部楼层
static void IntArray()
{
int[] numbers = new int[] { 1, 2, 3, 4, 5 };
foreach (int i in numbers)
{
switch (i)
{
case 3:
continue;
case 5:
Console.WriteLine(i);
...
回复

使用道具 举报

千问 | 2011-8-8 16:46:23 | 显示全部楼层
如果等于3就用continue跳出...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行