zoukankan      html  css  js  c++  java
  • 17、数组

    1、数组申明和初始化

      申明语法:

      string[] Mystr;

      int[] Myint;

      初始化

      int [] myInt

      myInt=new int[7];

      int [] myInt1= new int[7];

      int[] myInt=new int [7]{11,12,13,14,15,16,17};

      int[] myInt=new int []{11,12,13,14,15,16,17};

      int[] myInt={11,12,13,14,15,16,17};

    2、访问数组

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] myint = new int[7] { 1, 2, 3, 4, 5, 6, 7 };
                
                for(int i = 0; i<myint.Length; i++)
                {
                    Console.WriteLine(myint[i].ToString());
                    
                }
                Console.ReadLine();
            }
        }
    }

    三、foreach迭代

      foreach可以隐藏集合类型的内部实现方法,从而更加有效地处理集合类型元素。

      通过foreach打循环语句,可以循环列举某集合内的元素,并对各元素执行一次相关的嵌入语句。

    语法:

      foreach(类型 迭代变量 in 被迭代的表达式或集合变量)

          {

            处理语句

          }

      

     int[] myint = new int[7] { 1, 2, 3, 4, 5, 6, 7 };
                
                foreach(int i in myint)
                {
                    Console.WriteLine(i.ToString());
                    
                }
                Console.ReadLine();

    四、foreach规则

    五、存入引用类型

    class ywj
        {
            public ywj(string n,int a)
            {
                this.name = n;
                this.age = a;
            }
            public string name
            { get; set; }
            
            public int age
            { get; set; }
        }
    ywj y1=new ywj("张三",30);
                ywj y2 = new ywj("李四", 31);
    
                ywj [] myywj=new ywj[2]{ y1,y2 };
                foreach (ywj i in myywj)
                {
                    Console.WriteLine("姓名:{0},年龄:{1}",i.name.ToString(),i.age);
                    
                }
                Console.ReadLine();

      

  • 相关阅读:
    024 Go语言基础之文件操作
    023 Go语言标准库之log
    022 Go语言标准库之flag
    021 Go语言标准库之time
    019 Go语言基础之单元测试
    020 Go语言标准库之fmt
    数据导出为Excel(未完)
    .net+EF+mvc通过EasyUI的DataGrid实现增删改查
    EasyUI入门,DataGrid(数据表格)
    基于jQuery的用户界面插件集合---EasyUI
  • 原文地址:https://www.cnblogs.com/zytr/p/14743168.html
Copyright © 2011-2022 走看看