Finished Creating an Extension Method
This commit is contained in:
parent
7ac104a924
commit
7756047de1
20
Features/MyLinq.cs
Normal file
20
Features/MyLinq.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@ namespace Features
|
||||
{
|
||||
new Employee {Id = 3, Name = "Alex"}
|
||||
};
|
||||
|
||||
Console.WriteLine(sales.MyLinqCount());
|
||||
|
||||
var enumerator = developers.GetEnumerator();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user