Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Length of any Collection in C#
//#mode simple
using System;
using System.Collections;
using System.IO;
//This is a joke. Don't use
public static int Main(string[] Args)
return 0;
/// <summary>
/// Gets the Size of **any** enumerable object
/// </summary>
/// <returns>Element Count of the enumerable collection</returns>
private static long EnumerableSize(IEnumerable A)
//Get Temporary Name
var D=Path.GetTempFileName();
//State of the Art File to Directory Conversion (TODO: Async)
//Loop over all items
foreach(var Item in A)
//Create file
var F=Path.GetTempFileName();
//Move to our Directory
//Count Entries in the Directory
long Count = Directory.GetFiles(D).LongLength;
//Return Element Count
return Count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.