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

    运行结果:

  • 相关阅读:
    Linux 间网线直连
    Ubuntu 14.04安装配置NFS
    Android Native IPC 方案支持情况
    使用WindowsAPI获取录音音频
    Ubuntu 64编译32位程序
    TensorFlow 安装 Ubuntu14.04
    纯css实现表单输入验证
    安装ELectron失败解决方案
    正则学习
    常见web攻击
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/6505001.html
Copyright © 2011-2022 走看看