using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
        foreach (int number in numbers)
        {
            if (number % 2 == 0)
            {
                continue; // 跳过偶数,继续下一次循环
            }
            Console.WriteLine(number); // 只会输出奇数:1, 3, 5
        }
    }
}foreach 循环用于遍历集合中的每个元素。continue 语句用于跳过当前循环的剩余部分,并继续执行下一次循环。number 是偶数时,continue 会跳过 Console.WriteLine(number),因此只会输出奇数。上一篇:c# foreach跳出循环
下一篇:c# webrtc
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站