zoukankan      html  css  js  c++  java
  • C#遍历数组

    在C#中,可以使用foreach语句来遍历数组的元素:
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                // C#遍历数组-www.baike369.com
                int odd = 0; // 奇数
                int eve = 0; // 偶数
                int[] array = new int[100];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = i*5;
                }
                foreach (int j in array)
                {
                    if (j % 2 == 0)
                        eve++;
                    else
                        odd++;
                }
                Console.WriteLine("奇数有" + odd + "个");
                Console.WriteLine("偶数有" + eve + "个");
                Console.ReadLine();
            }
        }
    }

    运行结果:
     
    奇数有50个
    偶数有50个

  • 相关阅读:
    pytest框架
    Zabbix第九章(zabbix自定义item)
    Zabbix第七章(Zabbix监控本地)
    Zabbix第五章(配置zabbix的语言)
    Zabbix第四章(zabbix-server安装)
    Zabbix第二章(下载)
    Zabbix第一章(简介)
    线性筛
    Eratosthenes筛法
    质数判定
  • 原文地址:https://www.cnblogs.com/melao2006/p/4241681.html
Copyright © 2011-2022 走看看