using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Senthil.Utilities
{
public static class Itertools
{
public static IEnumerable<T> Chain<T>(params IEnumerable<T>[] iterables)
{
foreach(IEnumerable<T> iterable in iterables)
{
foreach (T t in iterable)
{
yield return t;
}
}
} public static IEnumerable<T> Cycle<T>(IEnumerable<T> iterable)
{
while (true)
{
foreach (T t in iterable)
{
yield return t;
}
}
} public static IEnumerable<T[]> Zip<T>(params IEnumerable<T>[] iterables)
{
IEnumerator<T>[] enumerators = Array.ConvertAll(iterables, (iterable) => iterable.GetEnumerator()); T[] values = new T[enumerators.Length]; while (true)
{
int index = 0; foreach (IEnumerator<T> enumerator in enumerators)
{
if (!enumerator.MoveNext())
yield break; values[index++] = enumerator.Current;
} yield return values;
}
}
public static IEnumerator<T>[] Tee<T>(IEnumerator<T> source, int count)
{
List<T> tValues = new List<T>();
IEnumerator<T>[] results = new IEnumerator<T>[count]; for (int i = 0; i < count; ++i)
{
int currentLocation = 0; results[i] = CreateEnumerator(source, new EnumeratorState<T>() { CurrentLocation = currentLocation, TValues = tValues });
} return results;
} private static IEnumerator<T> CreateEnumerator<T>(IEnumerator<T> source, EnumeratorState<T> state)
{
while (true)
{
if (state.CurrentLocation < state.TValues.Count)
{
yield return state.TValues[state.CurrentLocation++];
}
else
{
if (source.MoveNext())
{
state.TValues.Add(source.Current);
state.CurrentLocation = state.TValues.Count;
yield return source.Current;
}
else
{
break;
}
}
}
} class EnumeratorState<T>
{
internal int CurrentLocation { get; set; }
internal List<T> TValues { get; set; }
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Senthil.Utilities
{
public static class Itertools
{
public static IEnumerable<T> Chain<T>(params IEnumerable<T>[] iterables)
{
foreach(IEnumerable<T> iterable in iterables)
{
foreach (T t in iterable)
{
yield return t;
}
}
} public static IEnumerable<T> Cycle<T>(IEnumerable<T> iterable)
{
while (true)
{
foreach (T t in iterable)
{
yield return t;
}
}
} public static IEnumerable<T[]> Zip<T>(params IEnumerable<T>[] iterables)
{
IEnumerator<T>[] enumerators = Array.ConvertAll(iterables, (iterable) => iterable.GetEnumerator()); T[] values = new T[enumerators.Length]; while (true)
{
int index = 0; foreach (IEnumerator<T> enumerator in enumerators)
{
if (!enumerator.MoveNext())
yield break; values[index++] = enumerator.Current;
} yield return values;
}
}
public static IEnumerator<T>[] Tee<T>(IEnumerator<T> source, int count)
{
List<T> tValues = new List<T>();
IEnumerator<T>[] results = new IEnumerator<T>[count]; for (int i = 0; i < count; ++i)
{
int currentLocation = 0; results[i] = CreateEnumerator(source, new EnumeratorState<T>() { CurrentLocation = currentLocation, TValues = tValues });
} return results;
} private static IEnumerator<T> CreateEnumerator<T>(IEnumerator<T> source, EnumeratorState<T> state)
{
while (true)
{
if (state.CurrentLocation < state.TValues.Count)
{
yield return state.TValues[state.CurrentLocation++];
}
else
{
if (source.MoveNext())
{
state.TValues.Add(source.Current);
state.CurrentLocation = state.TValues.Count;
yield return source.Current;
}
else
{
break;
}
}
}
} class EnumeratorState<T>
{
internal int CurrentLocation { get; set; }
internal List<T> TValues { get; set; }
}
}
}
解决方案 »
- C#实现文件夹的everyone读写功能,并且包括该文件下的子文件
- rdlc 报表如何做到每一页都有入库单号
- 菜鸟继续提问。VS 2005快捷键!~~~~~~~~
- 一个关于变量刷新的问题,请各位前辈帮忙
- 关于XML的问题......
- winform的程序为什么设置控件的无效??
- 在线急等!!!如何把一个表中的数据字段绑订到模板列的DropDownList中???
- devexpress中xtragrid控件判断该行是否被选中怎样判断
- 新手问题。自动生成数据库连接控件
- 求救!装了VS.net后新建项目时它显示“VC软件包不可用或未注册”
- 一个简单的存储过程的问题
- object e0292b9ed559da7d 是用什么混淆器。能反混淆么?
<T> 是泛型,在实例化时再具体指定