@@ -9,9 +9,32 @@ namespace Extensions
99{
1010 public static class IEnumerableExtensions
1111 {
12- //public static void Each<T>(this IEnumerable<T> source, Action<T> action) => For.Each(source, action);
12+ [ DebuggerStepThrough ]
13+ public static void Each < T > ( this IEnumerable < T > source , Action < T > action )
14+ {
15+ foreach ( var item in source )
16+ action ( item ) ;
17+ }
18+
19+ /// <summary>
20+ /// For shortcut, no side effects
21+ /// </summary>
22+ [ DebuggerStepThrough ]
23+ public static void Each < T > ( this IEnumerable source , Action < T > action )
24+ {
25+ foreach ( var item in source )
26+ action ( ( T ) item ) ;
27+ }
1328
14- //public static void Each<T>(this IEnumerable source, Action<T> action) => For.Each(source, action);
29+ /// <summary>
30+ /// For shortcut with index, no side effects
31+ /// </summary>
32+ [ DebuggerStepThrough ]
33+ public static void EachIndex < T > ( this IEnumerable < T > source , Action < T , int > action )
34+ {
35+ var i = 0 ;
36+ Each ( source , item => action ( item , i ++ ) ) ;
37+ }
1538
1639 public static IEnumerable < T > Except < T > ( this IEnumerable < T > list , IEnumerable < T > except , Func < T , T , bool > comparer ) =>
1740 list . Except ( except , new KeyEqualityComparer < T > ( comparer ) ) ;
@@ -81,32 +104,5 @@ public static bool AreAllSame<T>(this IEnumerable<T> enumerable)
81104
82105 return true ;
83106 }
84-
85- [ DebuggerStepThrough ]
86- public static void Each < T > ( this IEnumerable < T > source , Action < T > action )
87- {
88- foreach ( var item in source )
89- action ( item ) ;
90- }
91-
92- /// <summary>
93- /// For shortcut, no side effects
94- /// </summary>
95- [ DebuggerStepThrough ]
96- public static void Each < T > ( this IEnumerable source , Action < T > action )
97- {
98- foreach ( var item in source )
99- action ( ( T ) item ) ;
100- }
101-
102- /// <summary>
103- /// For shortcut with index, no side effects
104- /// </summary>
105- [ DebuggerStepThrough ]
106- public static void EachIndex < T > ( this IEnumerable < T > source , Action < T , int > action )
107- {
108- var i = 0 ;
109- Each ( source , item => action ( item , i ++ ) ) ;
110- }
111107 }
112108}
0 commit comments