zoukankan      html  css  js  c++  java
  • List

     1 using System;
     2 using System.Collections.Generic;
     3 
     4 public class ListTest
     5 {
     6     public static void Main()  
     7     {
     8         List<string> fruits = new List<string>();
     9 
    10         fruits.Add("Apple");
    11         fruits.Add("Banana");
    12         fruits.Add("Carrot");
    13 
    14         Console.WriteLine( "Count: {0}", fruits.Count );
    15 
    16         PrintValues1( fruits );
    17         PrintValues2( fruits );
    18         PrintValues3( fruits );
    19     }
    20 
    21     //List实现了IList接口
    22     static void PrintValues1( IList<string> myList )
    23     {
    24         for(int i=0; i<myList.Count; i++ )
    25             Console.Write( "{0}
    ", myList[i] );
    26     }
    27 
    28     static void PrintValues2( IList<string> myList )
    29     {
    30         foreach( string item in myList )
    31             Console.Write( "{0}
    ", item );
    32     }
    33 
    34     static void PrintValues3( IEnumerable<string> myList )  
    35     {
    36         IEnumerator<string> myEnumerator = myList.GetEnumerator();
    37         while ( myEnumerator.MoveNext() )
    38             Console.Write( "{0}
    ", myEnumerator.Current );
    39         Console.WriteLine();
    40     }
    41 }
  • 相关阅读:
    syslog命令
    linux命令 info
    Alibaba(阿里) RocketMQ入门实例
    java基础-学java util类库总结
    java 23种设计模式教程
    Linux
    Scrapy框架
    MongoDB的安装与使用
    爬虫小案例——爬取天猫
    爬虫小案例——爬取豆瓣电影
  • 原文地址:https://www.cnblogs.com/GoldenEllipsis/p/10558588.html
Copyright © 2011-2022 走看看