zoukankan      html  css  js  c++  java
  • C# 2.0学习之集合1

     编译与执行:
    csc tokens.cs
                tokens



    tokens.cs :


    //Copyright (C) Microsoft Corporation.  All rights reserved.

    // tokens.cs
    using System;
    // The System.Collections namespace is made available:
    using System.Collections;

    // Declare the Tokens class:
    public class Tokens : IEnumerable
    {
       private string[] elements;

       Tokens(string source, char[] delimiters)
       {
          // Parse the string into tokens:
          elements = source.Split(delimiters);
       }

       // IEnumerable Interface Implementation:
       //   Declaration of the GetEnumerator() method
       //   required by IEnumerable
       public IEnumerator GetEnumerator()
       {
          return new TokenEnumerator(this);
       }

       // Inner class implements IEnumerator interface:
       private class TokenEnumerator : IEnumerator
       {
          private int position = -1;
          private Tokens t;

          public TokenEnumerator(Tokens t)
          {
             this.t = t;
          }

          // Declare the MoveNext method required by IEnumerator:
          public bool MoveNext()
          {
             if (position < t.elements.Length - 1)
             {
                position++;
                return true;
             }
             else
             {
                return false;
             }
          }

          // Declare the Reset method required by IEnumerator:
          public void Reset()
          {
             position = -1;
          }

          // Declare the Current property required by IEnumerator:
          public object Current
          {
             get
             {
                return t.elements[position];
             }
          }
       }

       // Test Tokens, TokenEnumerator

       static void Main()
       {
          // Testing Tokens by breaking the string into tokens:
          Tokens f = new Tokens("This is a well-done program.",
             new char[] {' ','-'});
          foreach (string item in f)
          {
             Console.WriteLine(item);
          }
       }
    }

  • 相关阅读:
    w10更新
    java.lang.Integer cannot be cast to java.math.BigDecimal
    加法add 乘法multiply
    iterator,hasNext,next
    购物车全部数据,带商品信息
    ERRORinit datasource error, url: jdbc:mysql://localhost:3306/xxxxxx?useUnicode=true&characterEncoding=gbk&serverTimezone=GMT&useSSL=false
    Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:
    创建一个场景
    window系统已发布,等待更新
    [转]向量(矩阵)范式理解(0范式,1范式,2范式,无穷范式)
  • 原文地址:https://www.cnblogs.com/llbofchina/p/434152.html
Copyright © 2011-2022 走看看