TryGetNonEnumeratedCount: New LINQ extensions series

var pair1 = new[]
{
"Man1",
"Woman1",
};
var pair2 = new[]
{
"Man2",
"Woman2",
};
var pair3 = new[]
{
"Man3",
"Woman3",
};
IEnumerable<string> concatPairs = pair1.Concat(pair2).Concat(pair3);
var countForce = concatPairs.Count();
if (countForce > 0)
{
// do some stuff
Console.WriteLine("Enforce enumeration to count");
Console.WriteLine(countForce);
}
if (concatPairs.TryGetNonEnumeratedCount(out var count))
{
// do some stuff
Console.WriteLine("Try to count with out enforcing enumeration");
Console.WriteLine(count);
}

--

--

Maytham is a passionate software developer with more than ten years of experience. His motivation is to help transform ideas into production ready systems.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maytham Fahmi

Maytham Fahmi

Maytham is a passionate software developer with more than ten years of experience. His motivation is to help transform ideas into production ready systems.