Created
November 7, 2011 16:08
-
-
Save leviwilson/1345379 to your computer and use it in GitHub Desktop.
Example Extension Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class EnumerableExtensions | |
| { | |
| public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) | |
| { | |
| foreach (var item in items) | |
| action(item); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class HashCode | |
| { | |
| public static int ComputeHashCode(params object[] logicalKeys) | |
| { | |
| var hash = 13; | |
| foreach (var logicalKey in logicalKeys) | |
| { | |
| hash = hash * 7 + (logicalKey == null ? 0 : logicalKey.GetHashCode()); | |
| } | |
| return hash; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class IntegerExtensions | |
| { | |
| public static void Times(this int n, Action<int> action) | |
| { | |
| Enumerable.Range(0, n).ForEach(action); | |
| } | |
| } |
leviwilson
commented
Jan 3, 2012
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment