C# 2.0学习之--集合
来源:互联网 发布:mac散热声音大怎么办 编辑:程序博客网 时间:2024/06/05 04:02
csc tokens.cstokens
// 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);
}
}
}
tokens.cs :
//Copyright (C) Microsoft Corporation. All rights reserved.
- C# 2.0学习之--集合
- C# 2.0学习之--集合2
- C#学习笔记之五:集合
- C#学习笔记之ArrayList集合
- C#学习笔记之Hashtable集合
- C#学习笔记之——集合
- C#学习之旅之数组与集合
- c#集合的学习
- c#集合之三哈希表
- C#之集合浅谈
- C#集合之Queue
- C# 之 集合ArrayList
- C#复习之集合
- C#集合之STACK
- C#集合之Stack
- C#集合之SortedList
- C#之集合概述
- C#学习笔记之集合(入门经典 11.)
- 宽带路由器
- 我错了吗?
- C# 2.0学习之--匿名代理
- C# 2.0学习之--数组
- 好心情,好收获
- C# 2.0学习之--集合
- 开始写Win32 Application程序了
- C# 2.0学习之--集合2
- 中断方式实现发送数据串口驱动
- 有用的网址
- C# 2.0学习之--条件编译
- C# 2.0学习之--代理1
- C# 2.0学习之--代理2
- 周末到了~周末愉快哦