Finished Creating an Extension Method
parent
7ac104a924
commit
7756047de1
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Features
|
||||
{
|
||||
public static class MyLinq
|
||||
{
|
||||
// Implement a customized LINQ using extension
|
||||
public static int MyLinqCount<T>(this IEnumerable<T> sequence)
|
||||
{
|
||||
// Any IEnumerable<T> instance can use this method now as extension
|
||||
int count = 0;
|
||||
foreach (var item in sequence)
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,6 +20,8 @@ namespace Features
|
|||
new Employee {Id = 3, Name = "Alex"}
|
||||
};
|
||||
|
||||
Console.WriteLine(sales.MyLinqCount());
|
||||
|
||||
var enumerator = developers.GetEnumerator();
|
||||
|
||||
while (enumerator.MoveNext())
|
||||
|
|
Loading…
Reference in New Issue