zoukankan      html  css  js  c++  java
  • 泛型集合List(C#)

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ListDemo
     7 {
     8 class Program
     9 {
    10 static void Main(string[] args)
    11 {
    12 //泛型集合的基本使用
    13 List<int> scoreList = new List<int>();
    14 scoreList.Add(98);
    15 scoreList.Add(28);
    16 scoreList.Add(38);
    17 scoreList.Add(78);
    18 scoreList.Add(88);
    19 //List<string> nameList = new List<string>();
    20 scoreList.Insert(2, 70);
    21 //获取元素总数
    22 Console.WriteLine("获取元素总数:"+scoreList.Count );
    23 Console.WriteLine("_________________");
    24 //Console.ReadLine();
    25 //遍历集合
    26 Console.WriteLine("遍历输出在第一种方法:");
    27 foreach (int score in scoreList)
    28 {
    29 Console.WriteLine(score);
    30 }
    31 Console.WriteLine("_________________");
    32 Console.WriteLine("遍历输出在第二种方法:");
    33 for (int i = 0; i < scoreList.Count; i++)
    34 {
    35 Console.WriteLine(scoreList[i]);
    36 }
    37 //删除一个元素
    38 Console.WriteLine("_________________");
    39 Console.WriteLine(" 删除一个元素");
    40 scoreList.Remove(70);
    41 scoreList.Remove(2);
    42 for (int i = 0; i < scoreList.Count; i++)
    43 {
    44 Console.WriteLine(scoreList[i]);
    45 }
    46 Console.WriteLine("_________________");
    47 Console.WriteLine("清除所有元素");
    48 scoreList.Clear();
    49 Console.WriteLine("获取元素总数:" + scoreList.Count);
    50 Console.ReadLine();
    51 }
    52 }
    53 }
    View Code

    运行结果:

  • 相关阅读:
    DirectX11 With Windows SDK--35 粒子系统
    Xilinx FPGA 的 DNA 加密
    IIC
    蜂鸟E203系列—— SPI 设计
    SPI
    蜂鸟E203系列—— UART 设计
    蜂鸟E203系列——按键中断设计
    蜂鸟E203系列——Windows下运行hello world例程
    蜂鸟E203系列——定时器中断设计
    什么才是定制化IDE的核心价值?
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/6505001.html
Copyright © 2011-2022 走看看