zoukankan      html  css  js  c++  java
  • C#数组初始化的几种方式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace OneArray
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] arrOld;                                //数组初始化的几种方式,注意赋值利用 {} 实现。
                arrOld=new int[5]{ 30, 32, 40, 25, 35 };       
                int[] arrOld1 = {30,20,212 };
                int[] arrOld2 = new int[4] { 1, 2, 3, 4 };
                int[] testArray=new int[10];
                for (int i = 0; i < 10; i++)
                {
                    testArray[i] = i * 3;                    //对数组赋值前需要初始化数组长度
                }
                Console.WriteLine("员工年龄:");
                foreach (int n in arrOld)                     //使用foreach语句循环遍历一维数组中的元素
                {
                    Console.WriteLine("{0}", n + "");     //输出数组中的元素
                }
                Console.ReadLine();
            }
        }
    }

     试着修改一个数组的小demo,发现竟然改不出来,对语法不熟悉。编程还是要踏踏实实敲代码,切记眼高手低,光看书是不行的。

  • 相关阅读:
    Fusion access
    组网架构
    DHCP中继
    Vxlan配置
    redis多实例
    ansible实现redis角色
    ansible如何ssh免密链接(基于key验证)
    MySQL主从复制
    MySQL范例
    Ubuntu2004安装
  • 原文地址:https://www.cnblogs.com/stringAdmin/p/7489756.html
Copyright © 2011-2022 走看看