Created
June 16, 2011 07:59
-
-
Save anonymous/1028862 to your computer and use it in GitHub Desktop.
This file contains 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 int Count<TSource>(this IEnumerable<TSource> source) { | |
if (source == null) { | |
throw Error.ArgumentNull("source"); | |
} | |
var collectionT = source as ICollection<TSource>; | |
if (collectionT != null) { | |
return collectionT.Count; | |
} | |
var collection = source as ICollection; | |
if (collection != null) { | |
return collection.Count; | |
} | |
int num = 0; | |
using (IEnumerator<TSource> enumerator = source.GetEnumerator()) { | |
while (enumerator.MoveNext()) { | |
num++; | |
} | |
} | |
return num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment