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 }
  • 相关阅读:
    Coursera Algorithm II PA2 Q2
    Coursera Algorithm Part II PA2
    实现 memcpy 函数
    超人
    Proxy 模式
    【6】锋利的 jQuery 笔记
    【3】Chrome 的一些常用操作
    HTML 待解决与已解决问题
    CSS 待解决问题
    JS 一些常用技巧
  • 原文地址:https://www.cnblogs.com/GoldenEllipsis/p/10558588.html
Copyright © 2011-2022 走看看