本文整理汇总了C#中System.Linq.Enumerable.AsEnumerable<TSource>方法的典型用法代码示例。如果您正苦于以下问题:C# Enumerable.AsEnumerable<TSource>方法的具体用法?C# Enumerable.AsEnumerable<TSource>怎么用?C# Enumerable.AsEnumerable<TSource>使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.AsEnumerable<TSource>方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Where
// Custom class.
class Clump<T> : List<T>
{
// Custom implementation of Where().
public IEnumerable<T> Where(Func<T, bool> predicate)
{
Console.WriteLine("In Clump's implementation of Where().");
return Enumerable.Where(this, predicate);
}
}
static void AsEnumerableEx1()
{
// Create a new Clump<T> object.
Clump<string> fruitClump =
new Clump<string> { "apple", "passionfruit", "banana",
"mango", "orange", "blueberry", "grape", "strawberry" };
// First call to Where():
// Call Clump's Where() method with a predicate.
IEnumerable<string> query1 =
fruitClump.Where(fruit => fruit.Contains("o"));
Console.WriteLine("query1 has been created.\n");
// Second call to Where():
// First call AsEnumerable() to hide Clump's Where() method and thereby
// force System.Linq.Enumerable's Where() method to be called.
IEnumerable<string> query2 =
fruitClump.AsEnumerable().Where(fruit => fruit.Contains("o"));
// Display the output.
Console.WriteLine("query2 has been created.");
}
输出:
In Clump's implementation of Where(). query1 has been created. query2 has been created.