<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Renan Martins</title>
    <description>The latest articles on DEV Community by Renan Martins (@reenanms).</description>
    <link>https://dev.to/reenanms</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3523091%2Ff9c01d68-ddad-466d-8ee2-3539f2dd0c43.png</url>
      <title>DEV Community: Renan Martins</title>
      <link>https://dev.to/reenanms</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reenanms"/>
    <language>en</language>
    <item>
      <title>Resilience Through Adaptability: Solving the Problem, Not the Process</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 06 Jan 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/reenanms/resilience-through-adaptability-24b5</link>
      <guid>https://dev.to/reenanms/resilience-through-adaptability-24b5</guid>
      <description>&lt;p&gt;Plans change, APIs break, and priorities shift. It is simply part of the job.&lt;/p&gt;

&lt;p&gt;What separates great teams from average ones isn’t their ability to avoid change, but their ability to adapt to it without losing focus. In a world of rigid roadmaps, the most successful teams are those that view a plan as a starting point rather than a final destination.&lt;/p&gt;




&lt;h2&gt;
  
  
  Flexibility Is Strength, Not Chaos
&lt;/h2&gt;

&lt;p&gt;Being flexible does not mean working without a plan. On the contrary, it means understanding that plans are tools designed to help us navigate, not rules that must be followed at the expense of reality. When requirements shift, flexible teams do not waste time mourning the old plan. They immediately ask, “How can we adjust?” instead of “Why did this happen?”.&lt;/p&gt;

&lt;p&gt;This mindset shift is the foundation of team resilience. It turns a potential source of frustration into a moment of collective problem-solving.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Pragmatic Engineer’s Dilemma: Speed vs. Perfection
&lt;/h2&gt;

&lt;p&gt;One of the ultimate tests of professional flexibility happens during a production crisis. As engineers, we are trained to value "best practices" and clean architecture. However, flexibility requires the wisdom to know when the context demands speed over elegance.&lt;/p&gt;

&lt;p&gt;If you discover a critical production error and realize a simple fix (even if it doesn’t follow every best practice) can restore service in five minutes, while the "perfect" solution would take five days, you must be flexible enough to choose the fast path.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fix the fire first:&lt;/strong&gt; Apply the best solution you can within the time you actually have to stop the bleeding. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Acknowledge the debt:&lt;/strong&gt; Choosing a quick fix isn't about being a bad engineer, it's a strategic trade-off to protect the user experience. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Plan the future:&lt;/strong&gt; Flexibility requires a follow-up. You must plan the "right" fix as a future improvement to clear the technical debt you just created. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A team that refuses to be flexible during an outage because they "only write perfect code" is failing the business. True professionalism is knowing when to use a bandage and when to perform surgery. You fix the fast way in the time that you have, then you plan the future improvement.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Flexibility Looks Like in Practice
&lt;/h2&gt;

&lt;p&gt;Flexibility is a daily habit, not just a crisis response. It shows up in small but significant ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adjusting sprint goals&lt;/strong&gt; when priorities evolve or a new blocker is discovered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Welcoming new ideas&lt;/strong&gt; mid-development, even if it means changing a minor implementation detail.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Helping teammates&lt;/strong&gt; outside your usual scope when needed, such as a developer helping with documentation or manual testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Being open to feedback&lt;/strong&gt; even when it challenges your view or requires you to redo work you were proud of.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Cost of Rigidity
&lt;/h2&gt;

&lt;p&gt;When teams are too rigid, they become fragile. They stick to the original plan even when it no longer makes sense, leading to "feature building" for the sake of checking a box rather than delivering value. Rigid teams often focus more on following the rules than solving the problem, which eventually leads to friction and missed opportunities.&lt;/p&gt;

&lt;p&gt;A flexible team isn’t unpredictable, it’s resilient. By being willing to change, you ensure that the team's energy is always focused on the most impactful work available.&lt;/p&gt;




&lt;h2&gt;
  
  
  Balance Between Stability and Adaptability
&lt;/h2&gt;

&lt;p&gt;A flexible team isn't one without structure. You still keep processes, but you don’t let them become cages. It’s like writing code: clean architecture gives you the confidence to refactor safely.&lt;/p&gt;

&lt;p&gt;If your team has mastered communication, stays organized, and shares knowledge, you have the foundation needed to change without breaking the system or the team's spirit. Stability provides the safety net that makes adaptability possible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Flexibility is professionalism under uncertainty.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The best teams don’t fight change, they grow through it. In the world of software, the only constant is change. The faster you learn to embrace it, the better your team and your product will be.&lt;/p&gt;




&lt;p&gt;✅ That's all, folks!&lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let's Connect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>peopleoverpixels</category>
      <category>buildingbetterteams</category>
      <category>beyondcode</category>
      <category>flexibility</category>
    </item>
    <item>
      <title>Knowledge Sharing: Strong Teams Share What They Know</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 16 Dec 2025 21:04:37 +0000</pubDate>
      <link>https://dev.to/reenanms/knowledge-sharing-strong-teams-share-what-they-know-49n1</link>
      <guid>https://dev.to/reenanms/knowledge-sharing-strong-teams-share-what-they-know-49n1</guid>
      <description>&lt;p&gt;If only one person knows how something works, your team doesn't really know it yet.&lt;br&gt;
After years of working in different teams, I've learned that long-term success doesn't come from individual brilliance. It comes from shared understanding.&lt;br&gt;
Teams that rely on a few key people may move fast at first, but they become fragile.&lt;br&gt;
One vacation, one sick day, or one resignation is enough to slow everything down.&lt;br&gt;
Knowledge sharing isn't just a nice-to-have.&lt;br&gt;
It's what turns individual expertise into team strength, and effort into sustainable progress.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Knowledge Sharing Really Matters
&lt;/h2&gt;

&lt;p&gt;Code changes, tools evolve, and people move on.&lt;br&gt;
But when knowledge is shared, the team stays strong and independent.&lt;br&gt;
When it isn't, a single absence, vacation, or resignation can slow down or even freeze an entire project.&lt;br&gt;
When information isn't shared, progress becomes dependent on individuals. Shared knowledge turns a group of individuals into a resilient team.&lt;/p&gt;




&lt;h2&gt;
  
  
  Daily Sharing Builds Alignment
&lt;/h2&gt;

&lt;p&gt;Some of the most valuable knowledge sharing happens in small moments.&lt;/p&gt;

&lt;p&gt;Daily meetings are not just for status updates, they are opportunities to share:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a small discovery&lt;/li&gt;
&lt;li&gt;a mistake that taught a lesson&lt;/li&gt;
&lt;li&gt;a shortcut or improvement&lt;/li&gt;
&lt;li&gt;a concern others might face soon
These small insights, shared consistently, prevent repeated mistakes and keep everyone aligned.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When One Teaches, Everyone Grows
&lt;/h2&gt;

&lt;p&gt;While daily sharing is important, dedicated knowledge-sharing sessions are even more powerful. Internal training sessions, demos, or short presentations allow one team member to share deeper expertise with the rest of the team.&lt;br&gt;
They spread ownership, reduce dependency on single experts, and raise the overall level of the group.&lt;br&gt;
Teaching isn't a distraction from work, it is part of the work.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pair Programming as a Knowledge Bridge
&lt;/h2&gt;

&lt;p&gt;Pair programming is one of the most effective tools for sharing knowledge and experience. The team members work together, share knowledge and learn together, keep team members:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;communicating constantly&lt;/li&gt;
&lt;li&gt;learning different approaches&lt;/li&gt;
&lt;li&gt;understanding parts of the system they wouldn't touch alone
More than a coding technique, pair programming is a collaboration practice that spreads context and builds trust.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Building a Culture of Openness
&lt;/h2&gt;

&lt;p&gt;Knowledge sharing only works when people feel safe to speak, ask, and admit they don't know something.&lt;br&gt;
Teams grow faster when learning is celebrated, and mistakes are treated as feedback, not failure.&lt;br&gt;
When curiosity is valued over ego, knowledge flows naturally.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Knowledge grows when it's shared.&lt;br&gt;
Teams don't become strong because a few people know everything. They become strong when everyone knows enough to move forward together.&lt;br&gt;
The best developers aren't the ones who know the most, they're the ones who help others know more.&lt;/p&gt;




&lt;p&gt;✅ That's all, folks!&lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let's Connect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>peopleoverpixels</category>
      <category>buildingbetterteams</category>
      <category>beyondcode</category>
      <category>knowledgesharing</category>
    </item>
    <item>
      <title>Moving Smarter, Not Faster: How Organization Shapes Great Teams</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 25 Nov 2025 15:00:00 +0000</pubDate>
      <link>https://dev.to/reenanms/moving-smarter-not-faster-how-organization-shapes-great-teams-2eg6</link>
      <guid>https://dev.to/reenanms/moving-smarter-not-faster-how-organization-shapes-great-teams-2eg6</guid>
      <description>&lt;p&gt;After years of working with different teams, one pattern became impossible to ignore: the teams that consistently delivered weren't the ones rushing or pushing harder.&lt;br&gt;
They were the ones who knew how to plan, prioritize, and bring clarity to chaos.&lt;/p&gt;

&lt;p&gt;The best teams don't move faster, they move &lt;em&gt;smarter&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In every project I've seen, chaos doesn't come from bad intentions or weak skills. It comes from a lack of organization.&lt;/p&gt;




&lt;h2&gt;
  
  
  When a Team Has Everything, Except Organization
&lt;/h2&gt;

&lt;p&gt;A few years ago, I joined a team that, at first glance, had everything going for them.&lt;br&gt;
They communicated well, they were technically strong, and they genuinely cared about the product. Even though,  there was something was deeply wrong: they were drowning.&lt;/p&gt;

&lt;p&gt;There was an almost one-year backlog of client customization requests, a full year of work waiting in line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It wasn't because the team was slow or inefficient.&lt;/li&gt;
&lt;li&gt;It wasn't because the requests were too complex.&lt;/li&gt;
&lt;li&gt;And, it definitely wasn't because the developers lacked skill.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The real issue was simpler, but more damaging: they had no structure to support their effort.&lt;/p&gt;

&lt;p&gt;Code organization was inconsistent and their processes weren't standardized.&lt;br&gt;
There was no predictable way to analyze, prioritize, or break down tasks, and because everything felt urgent, no one had the space to step back and ask: &lt;em&gt;"Why are we always behind?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;They weren't failing because of performance. They were failing because the chaos around them made improvement impossible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rebuilding Structure From the Inside Out
&lt;/h3&gt;

&lt;p&gt;When I moved into a leadership role, I didn't start by pushing the team to work harder or faster, actually, they were already doing that.&lt;/p&gt;

&lt;p&gt;Instead, we focused on the fundamentals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reorganizing parts of the codebase.&lt;/li&gt;
&lt;li&gt;Simplifying and clarifying process flows.&lt;/li&gt;
&lt;li&gt;Standardizing how requests were analyzed and sized.&lt;/li&gt;
&lt;li&gt;Reducing invisible work by making everything visible.&lt;/li&gt;
&lt;li&gt;Creating feedback loops to adjust our structure continuously.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We didn't introduce anything radical, just &lt;strong&gt;organization&lt;/strong&gt;, clarity, and repeatable habits.&lt;br&gt;
That changed everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  One Year Later: Completely Different Scenario
&lt;/h3&gt;

&lt;p&gt;Within a year, the transformation was huge.&lt;/p&gt;

&lt;p&gt;The backlog that once stretched over 12 months had shrunk to less than 3 months, and it kept trending down toward 1 month, a level the team once thought impossible.&lt;/p&gt;

&lt;p&gt;We did it without hiring more people, without major rewrites, and without extra pressure.&lt;/p&gt;

&lt;p&gt;The difference was structure.&lt;br&gt;
The difference was organization.&lt;br&gt;
The difference was finally giving the team the breathing room to think instead of just reacting.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Good Organization Actually Looks Like
&lt;/h2&gt;

&lt;p&gt;Good organization isn't about rigid processes, fancy tools, or adding layers of bureaucracy.&lt;br&gt;
It's about building clarity, predictability, and shared understanding so the team can focus on what matters: solving real problems.&lt;/p&gt;

&lt;p&gt;Here's what it really looks like inside a healthy, well-organized team&lt;/p&gt;

&lt;h3&gt;
  
  
  Clear Priorities
&lt;/h3&gt;

&lt;p&gt;Everyone knows what matters most and why.&lt;br&gt;
No guessing, no mixed signals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Visible Work
&lt;/h3&gt;

&lt;p&gt;Tasks, blockers, and progress are transparent.&lt;br&gt;
If work is invisible, it becomes unmanageable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Processes
&lt;/h3&gt;

&lt;p&gt;Not heavy frameworks, just small, consistent habits the team actually follows.&lt;/p&gt;

&lt;h3&gt;
  
  
  Predictable Code Structure
&lt;/h3&gt;

&lt;p&gt;Clean, organized code makes planning, reviewing, and improving easier for everyone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Space to Think
&lt;/h3&gt;

&lt;p&gt;When the team isn't drowning, they can improve, not just react.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Organization isn't about slowing teams down.&lt;br&gt;
It's what frees them to move intelligently, collaboratively, and confidently. Because at the end of the day:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Teams don't become great by moving faster, they become great by moving smarter!&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;This is what transforms effort into progress, and chaos into momentum.&lt;/p&gt;




&lt;p&gt;✅ That’s all, folks!&lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>peopleoverpixels</category>
      <category>buildingbetterteams</category>
      <category>beyondcode</category>
      <category>organization</category>
    </item>
    <item>
      <title>Talk Early, Fail Less: How Communication Builds Great Teams</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 11 Nov 2025 15:00:00 +0000</pubDate>
      <link>https://dev.to/reenanms/talk-early-fail-less-how-communication-builds-great-teams-3l4b</link>
      <guid>https://dev.to/reenanms/talk-early-fail-less-how-communication-builds-great-teams-3l4b</guid>
      <description>&lt;p&gt;Every great product starts with people, not code.&lt;br&gt;
This post kicks off my new series &lt;strong&gt;People Over Pixels&lt;/strong&gt;, where I share the &lt;em&gt;soft skills&lt;/em&gt; that I believe are more important than any framework, syntax, or architecture.&lt;br&gt;
After years of working in different teams, I’ve realized that the success of a product depends less on how we code, and more on how we communicate.&lt;/p&gt;




&lt;h2&gt;
  
  
  When One Missing Conversation Costs Million of Dollars
&lt;/h2&gt;

&lt;p&gt;In 1999, NASA lost the &lt;strong&gt;Mars Climate Orbiter&lt;/strong&gt;, a $125 million spacecraft. Not because of bad hardware, or a complex bug, but because two brilliant teams weren’t aligned. One used imperial units. The other used metric.&lt;br&gt;
A single misunderstanding destroyed years of work and one of the most advanced spacecraft ever built [1].&lt;br&gt;&lt;br&gt;
That story stuck with me because it shows something simple yet profound:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even the best engineers fail when they stop talking the same language.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why Teams Need to Talk
&lt;/h2&gt;

&lt;p&gt;The best teams I’ve worked with didn’t avoid problems, they talked about them early. They didn’t guess what others meant, they asked. They didn’t hide mistakes, they shared them before they grew.&lt;br&gt;
Communication isn’t about meetings or documentation. It’s about creating a &lt;em&gt;shared understanding&lt;/em&gt;, so everyone moves in the same direction.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Power of Asking Questions
&lt;/h2&gt;

&lt;p&gt;I used to stay quiet when I wasn’t 100% sure about something. I thought asking too many questions would make me look less experienced, but the truth is the opposite.&lt;br&gt;
The people who ask questions &lt;em&gt;make everyone smarter&lt;/em&gt;. They catch assumptions, expose risks, and help the team think more clearly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The best developers aren’t the ones who always know the answer, they’re the ones who make it safe for everyone to ask the hard questions.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Lessons from Toyota: Communication as Quality
&lt;/h2&gt;

&lt;p&gt;Toyota’s production system is famous for one rule: any worker on the line can pull the &lt;em&gt;andon cord&lt;/em&gt; to stop production if they see a problem.&lt;br&gt;
It doesn’t matter who you are, everyone is empowered to speak up. That culture of openness made Toyota one of the most consistent, high-quality manufacturers in the world.&lt;br&gt;
In software, "pulling the andon cord" means saying:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"I think we might have a problem here."&lt;/li&gt;
&lt;li&gt;"I’m not sure I understood this requirement."&lt;/li&gt;
&lt;li&gt;"Can we discuss another approach?"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s how teams build quality, not just in their code, but in their relationships.&lt;/p&gt;




&lt;h2&gt;
  
  
  Communication Is a Force Multiplier
&lt;/h2&gt;

&lt;p&gt;Good communication turns individual effort into collective success. It’s how teams stay aligned, fix problems faster, and build trust over time.&lt;br&gt;
When people talk, they discover solutions no one could find alone. When they stay silent, even the best code can’t save them.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Great teams aren’t made of the most talented individuals, they’re made of people who &lt;em&gt;talk, listen, and learn together&lt;/em&gt;. So, if you want your next project to succeed, don’t just focus on writing perfect code.&lt;br&gt;&lt;br&gt;
Focus on &lt;em&gt;creating conversations&lt;/em&gt; that lead to better code, because in the end:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Teams that talk early, fail less, and build more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;[1] &lt;a href="https://www.simscale.com/blog/nasa-mars-climate-orbiter-metric/" rel="noopener noreferrer"&gt;Simscale - When NASA Lost a Spacecraft Due to a Metric Math Mistake&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;✅ That’s all, folks!&lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>peopleoverpixels</category>
      <category>buildingbetterteams</category>
      <category>beyondcode</category>
      <category>communication</category>
    </item>
    <item>
      <title>Teaching My Team How to Build LINQ from Scratch</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 04 Nov 2025 15:00:00 +0000</pubDate>
      <link>https://dev.to/reenanms/teaching-my-team-how-to-build-linq-from-scratch-11p9</link>
      <guid>https://dev.to/reenanms/teaching-my-team-how-to-build-linq-from-scratch-11p9</guid>
      <description>&lt;p&gt;After weeks exploring &lt;code&gt;IEnumerable&lt;/code&gt;, &lt;code&gt;yield return&lt;/code&gt;, and &lt;code&gt;xUnit&lt;/code&gt;, we’ve reached the final step of our journey: &lt;strong&gt;building our own LINQ methods&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is the story of how I used this project to teach my team C# fundamentals and remove the illusion that LINQ is “something magical.”&lt;br&gt;&lt;br&gt;
It’s not magic, it’s just &lt;strong&gt;beautifully structured C# code&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why I Built This Project for My Team
&lt;/h2&gt;

&lt;p&gt;As a team lead, I noticed some developers using LINQ daily without really knowing how it worked.&lt;br&gt;&lt;br&gt;
So, I decided to create a simple project to teach them how to &lt;strong&gt;implement&lt;/strong&gt; LINQ-like methods from scratch.&lt;/p&gt;

&lt;p&gt;We used everything we learned throughout this series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; and iteration&lt;/li&gt;
&lt;li&gt;Extension methods&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yield return&lt;/code&gt; and deferred execution&lt;/li&gt;
&lt;li&gt;Unit testing with &lt;strong&gt;xUnit&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The complete project is available on GitHub:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/reenanms/My.Linq" rel="noopener noreferrer"&gt;github.com/reenanms/My.Linq&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Using the Test Project from the Previous Article
&lt;/h2&gt;

&lt;p&gt;In the last article, we wrote tests for &lt;code&gt;Where&lt;/code&gt; and &lt;code&gt;Any&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Now it’s time to make those tests pass with your own implamentation!&lt;/p&gt;

&lt;p&gt;We’ll create a new C# project called &lt;code&gt;MyLinq&lt;/code&gt; and add a class &lt;code&gt;LinqExtensions&lt;/code&gt; with empty methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LinqExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotImplementedException&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotImplementedException&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotImplementedException&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we’ll &lt;strong&gt;update our test project&lt;/strong&gt; to reference this one.&lt;/p&gt;

&lt;p&gt;Finally, replace this line in the tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Linq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;MyLinq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your tests will target your implementation instead of the real LINQ.&lt;/p&gt;




&lt;h2&gt;
  
  
  Implementing &lt;code&gt;.Where()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s our custom version of the Where method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method uses &lt;code&gt;yield return&lt;/code&gt; to generate results one by one, the same concept used internally by LINQ.&lt;br&gt;
Thanks to deferred execution, no new list is created in memory; items are returned as needed.&lt;br&gt;
Run your tests, and the &lt;code&gt;Where&lt;/code&gt; tests from the previous article should now pass ✅&lt;/p&gt;


&lt;h2&gt;
  
  
  Implementing &lt;code&gt;.Any()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now let’s implement Any.&lt;br&gt;
We’ll write two versions: one without parameters, and one that takes a condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first one checks if any element exists, while the second checks if any element matches a given condition.&lt;br&gt;
Simple, efficient, and clear.&lt;/p&gt;


&lt;h2&gt;
  
  
  Running the Tests
&lt;/h2&gt;

&lt;p&gt;Now, run all the tests again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is set up correctly, all tests should pass 🎉&lt;/p&gt;

&lt;p&gt;This moment is satisfying. Watching green check marks appear knowing you just rebuilt core LINQ behavior from scratch.&lt;/p&gt;




&lt;h2&gt;
  
  
  What The Team Learned
&lt;/h2&gt;

&lt;p&gt;When we finished this project, something changed in how my team approached C#.&lt;br&gt;
They realized:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LINQ isn’t “doing magic”, it’s just well-written extension methods.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; and &lt;code&gt;yield return&lt;/code&gt; are extremely powerful tools.&lt;/li&gt;
&lt;li&gt;Writing tests first helps clarify logic and prevents mistakes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It became one of our favorite learning sessions as a team.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up the Series
&lt;/h2&gt;

&lt;p&gt;This article closes the &lt;em&gt;From Blank to LINQ Mastery&lt;/em&gt; series, a journey that started when I blanked in an interview question about LINQ 😅&lt;br&gt;
Now, we’ve gone full circle: understanding it, rebuilding it, and teaching it.&lt;/p&gt;

&lt;p&gt;If you haven’t seen the previous articles, you can start from the beginning here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/when-i-went-blank-in-an-interview-and-what-i-learned-about-linq-41i5"&gt;When I Went Blank in an Interview – and What I Learned About LINQ&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/understanding-ienumerable-in-c-the-foundation-of-linq-5g6c"&gt;Understanding IEnumerable in C#: The Foundation of LINQ&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/how-extension-methods-unlock-linqs-magic-in-c-1jmd"&gt;How Extension Methods Unlock LINQ’s Magic in C#&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/cs-hidden-gem-how-yield-return-makes-iterators-simple-kno"&gt;C#’s Hidden Gem: How Yield Return Makes Iterators Simple&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/unit-testing-our-first-linq-like-methods-in-c-26jp"&gt;Unit Testing Our First LINQ-like Methods in C#&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teaching My Team How to Build LINQ from Scratch&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;✅ That’s all, folks!  &lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <title>Unit Testing Our First LINQ-like Methods in C#</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 28 Oct 2025 14:30:00 +0000</pubDate>
      <link>https://dev.to/reenanms/unit-testing-our-first-linq-like-methods-in-c-26jp</link>
      <guid>https://dev.to/reenanms/unit-testing-our-first-linq-like-methods-in-c-26jp</guid>
      <description>&lt;p&gt;Before we start writing our own LINQ methods, we’ll take a quick step back to prepare a strong foundation: &lt;strong&gt;unit testing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, we’ll use &lt;strong&gt;xUnit&lt;/strong&gt; to define how our LINQ-like methods &lt;em&gt;should behave&lt;/em&gt; before we even implement them.&lt;/p&gt;

&lt;p&gt;This approach will make our next article — where we start coding &lt;code&gt;Where&lt;/code&gt; and &lt;code&gt;Any&lt;/code&gt; — much easier to understand and validate.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Write Tests First?
&lt;/h2&gt;

&lt;p&gt;We’ve already learned about &lt;code&gt;IEnumerable&lt;/code&gt;, extension methods, and &lt;code&gt;yield return&lt;/code&gt;. Now it’s time to put that knowledge to work.&lt;br&gt;&lt;br&gt;
But instead of jumping directly into coding, we’ll describe how our methods are supposed to behave — using &lt;strong&gt;unit tests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Writing tests first gives us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clear definition of what each method should do.
&lt;/li&gt;
&lt;li&gt;Confidence that our implementation works.
&lt;/li&gt;
&lt;li&gt;Easier debugging later, since failing tests tell us exactly what’s wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the spirit of &lt;strong&gt;Test-Driven Development (TDD)&lt;/strong&gt; — write tests first, make them fail, then implement the logic until they pass.&lt;/p&gt;


&lt;h2&gt;
  
  
  Setting Up xUnit
&lt;/h2&gt;

&lt;p&gt;We’ll use &lt;strong&gt;xUnit&lt;/strong&gt;, a popular and lightweight testing framework for .NET.&lt;/p&gt;

&lt;p&gt;To create a new test project, open the terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new xunit &lt;span class="nt"&gt;-n&lt;/span&gt; MyLinq.Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, add the reference packages to the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;MyLinq.Tests
dotnet add MyLinq.Tests.csproj package xunit
dotnet add MyLinq.Tests.csproj package xunit.runner.visualstudio
dotnet add MyLinq.Tests.csproj package Microsoft.NET.Test.Sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can start writing tests inside the &lt;code&gt;MyLinq.Tests&lt;/code&gt; project.&lt;/p&gt;

&lt;p&gt;Each test class should focus on a single area of your code, for example, we’ll start with &lt;code&gt;Where&lt;/code&gt; and &lt;code&gt;Any&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Writing Our First Test: &lt;code&gt;Where&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s describe what we expect our future &lt;code&gt;Where&lt;/code&gt; method to do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;WhereOfArrayOfNumbers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myResultAfterFilter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfExpectNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myListOfExpectNumbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;myResultAfterFilter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’re calling the method &lt;code&gt;Where&lt;/code&gt;, which is a LINQ method, that in the future we are going to replace for our own.&lt;/p&gt;




&lt;h2&gt;
  
  
  Testing the &lt;code&gt;Any&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;Now let’s define tests for another common LINQ method: &lt;code&gt;Any&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AnyOfEmptyArray&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;False&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AnyOfArrayOfNumbers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;True&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AnyOfArrayOfNumbersWithFilterLessThenFive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;False&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AnyOfArrayOfNumbersWithFilterMoreThenFive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myListOfNumbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;True&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These tests give us a clear idea of what we expect from the implementation we’ll build next.&lt;/p&gt;




&lt;h2&gt;
  
  
  What’s Next
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;next article&lt;/strong&gt;, we’ll finally implement our own methods from scratch. The methods will have the same name as LINQ, and we are going to point the  test to the new namespace (intead &lt;code&gt;System.Linq&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;By starting with tests first, we’re setting the stage for a more predictable and maintainable LINQ-like library.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Write tests before implementation to define expected behavior.
&lt;/li&gt;
&lt;li&gt;xUnit makes it easy to structure and automate C# tests.
&lt;/li&gt;
&lt;li&gt;We’re now ready to implement our own LINQ methods!&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;✅ That’s all, folks!  &lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <title>C#’s Hidden Gem: How Yield Return Makes Iterators Simple</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 21 Oct 2025 14:30:00 +0000</pubDate>
      <link>https://dev.to/reenanms/cs-hidden-gem-how-yield-return-makes-iterators-simple-kno</link>
      <guid>https://dev.to/reenanms/cs-hidden-gem-how-yield-return-makes-iterators-simple-kno</guid>
      <description>&lt;p&gt;If you have ever tried to write an iterator manually, you know it can be painful. You need to manage indexes, track conditions, and build temporary lists.&lt;br&gt;
This article continues my series &lt;strong&gt;From Blank to LINQ Mastery&lt;/strong&gt;, exploring one of the simplest and most powerful features in C#, &lt;code&gt;yield return&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  What Are Iterators
&lt;/h2&gt;

&lt;p&gt;An iterator is a method or object that lets you go through a sequence one element at a time.&lt;br&gt;
In C#, it is any method that returns &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;br&gt;
The &lt;code&gt;foreach&lt;/code&gt; loop uses this mechanism internally to iterate over data.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Old Way (Without yield return)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetEvenNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This code works, but creates a new list in memory before returning the result.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Modern Way (With yield return)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetEvenNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With &lt;code&gt;yield return&lt;/code&gt;, C# automatically creates an iterator behind the scenes. Although, it's important to understand that this method behaves a little differently from what you might expect.&lt;br&gt;
It does not run from start to finish in one call.&lt;br&gt;
Instead, it pauses each time it returns a value and resumes from that exact point when the next element is requested.&lt;/p&gt;

&lt;p&gt;Here is a quick example that makes this clear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;SampleIterator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Start"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Middle"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"End"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have the method returning and iteratos, let's call it to see what happens when you iterate over it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SampleIterator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Before iteration"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Value: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After iteration"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before iteration
Start
Value: 1
Middle
Value: 2
End
After iteration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that function is not executed in its call. The method stops and resumes multiple times. Execution moves step by step, each time &lt;code&gt;MoveNext()&lt;/code&gt; is called in the background.&lt;br&gt;
This is known as &lt;strong&gt;deferred execution&lt;/strong&gt;, and it is the key to how LINQ operators process data lazily and efficiently.&lt;/p&gt;


&lt;h2&gt;
  
  
  Adding Control with yield break
&lt;/h2&gt;

&lt;p&gt;Sometimes you may want to stop the iteration early.&lt;br&gt;
That is where &lt;code&gt;yield break&lt;/code&gt; shows up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetFirstThreeEvenNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;++;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stops the sequence once three even numbers have been returned.&lt;br&gt;
No extra memory or complex logic required.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Tip: Be Careful with Database Iteration
&lt;/h2&gt;

&lt;p&gt;When using &lt;code&gt;yield return&lt;/code&gt; with data that comes from a database, remember that the database connection must remain open while the iterator is being read.&lt;br&gt;
If you close or dispose the connection before finishing the iteration, you will get exceptions or incomplete results.&lt;br&gt;
A good practice is to materialize the results (for example, with &lt;code&gt;.ToList()&lt;/code&gt;) before the connection is closed, unless you have full control over when and how the data is consumed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why It Matters for LINQ
&lt;/h2&gt;

&lt;p&gt;Most LINQ methods such as &lt;code&gt;.Where()&lt;/code&gt;, &lt;code&gt;.Select()&lt;/code&gt;, and &lt;code&gt;.Take()&lt;/code&gt; use &lt;code&gt;yield return&lt;/code&gt; internally.&lt;br&gt;
That is how LINQ can process data efficiently, creating values only when they are actually needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yield return&lt;/code&gt; simplifies iteration logic.&lt;/li&gt;
&lt;li&gt;It supports deferred execution, generating elements on demand.&lt;/li&gt;
&lt;li&gt;It is the foundation for how LINQ operators work behind the scenes.&lt;/li&gt;
&lt;li&gt;Be careful when combining it with database queries that depend on open connections.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;✅ That’s all, folks!  &lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <title>How Extension Methods Unlock LINQ’s Magic in C#</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 14 Oct 2025 14:30:00 +0000</pubDate>
      <link>https://dev.to/reenanms/how-extension-methods-unlock-linqs-magic-in-c-1jmd</link>
      <guid>https://dev.to/reenanms/how-extension-methods-unlock-linqs-magic-in-c-1jmd</guid>
      <description>&lt;p&gt;LINQ feels like magic: you call &lt;code&gt;.Where()&lt;/code&gt; on a list, and it just works. The secret? &lt;strong&gt;Extension methods.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Extension Methods?
&lt;/h2&gt;

&lt;p&gt;They allow us to “add” methods to existing classes without modifying them.&lt;/p&gt;

&lt;p&gt;To create one, you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;static class&lt;/strong&gt; to contain your extensions.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;static method&lt;/strong&gt; inside that class.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;this&lt;/code&gt; keyword&lt;/strong&gt; before the first parameter tells the compiler which type you’re extending.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;namespace&lt;/strong&gt; defines the scope, it'll apply just for the defined, to use in another &lt;code&gt;using&lt;/code&gt; statement must be used.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Adding Behavior to Strings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StringExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;IsCapitalized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsUpper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsCapitalized&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// True&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"world"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsCapitalized&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows the basic idea: we added a new method to &lt;code&gt;string&lt;/code&gt;, even though we don’t own the &lt;code&gt;string&lt;/code&gt; class.&lt;/p&gt;




&lt;h2&gt;
  
  
  Making Collections Smarter with Generics
&lt;/h2&gt;

&lt;p&gt;Extension methods get really useful when working with collections. Let’s make one that works with &lt;strong&gt;any type&lt;/strong&gt; and mimics the idea of LINQ’s &lt;code&gt;Where&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EnumerableExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;WhereNotNull&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;
    &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Charlie"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;filtered&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WhereNotNull&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filtered&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: Alice, Bob, Charlie&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we combined &lt;strong&gt;generics&lt;/strong&gt; (&lt;code&gt;T&lt;/code&gt;) with &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It works with any reference type.&lt;/li&gt;
&lt;li&gt;It feels just like a LINQ method (&lt;code&gt;WhereNotNull&lt;/code&gt; is similar to &lt;code&gt;Where(x =&amp;gt; x != null)&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Extension methods let you “teach” existing types new tricks.&lt;/li&gt;
&lt;li&gt;They can be simple (&lt;code&gt;string.IsCapitalized()&lt;/code&gt;) or collection-based (&lt;code&gt;WhereNotNull&amp;lt;T&amp;gt;()&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Always remember: &lt;strong&gt;static class + static method + &lt;code&gt;this&lt;/code&gt; keyword + correct namespace&lt;/strong&gt; = extension method.&lt;/li&gt;
&lt;li&gt;LINQ itself is just a big set of extension methods for &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;✅ That’s all, folks!  &lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding IEnumerable in C#: The Foundation of LINQ</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 07 Oct 2025 14:30:00 +0000</pubDate>
      <link>https://dev.to/reenanms/understanding-ienumerable-in-c-the-foundation-of-linq-5g6c</link>
      <guid>https://dev.to/reenanms/understanding-ienumerable-in-c-the-foundation-of-linq-5g6c</guid>
      <description>&lt;p&gt;If you’ve ever used a &lt;code&gt;foreach&lt;/code&gt; loop in C#, you’ve already been using &lt;code&gt;IEnumerable&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
It’s one of the most fundamental interfaces in .NET and forms the foundation of LINQ.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is IEnumerable?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; represents a sequence of elements that you can iterate over, one by one.&lt;br&gt;&lt;br&gt;
It powers the &lt;code&gt;foreach&lt;/code&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes, &lt;code&gt;foreach&lt;/code&gt; calls &lt;code&gt;GetEnumerator()&lt;/code&gt;, which returns an iterator.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Interface Definition
&lt;/h2&gt;

&lt;p&gt;Here’s the simplified definition of &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s surprisingly simple. It just promises that any type implementing it can return an &lt;code&gt;IEnumerator&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And what’s &lt;code&gt;IEnumerator&amp;lt;T&amp;gt;&lt;/code&gt;? It’s another interface that knows &lt;strong&gt;how to move through a sequence&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IDisposable&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Current&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;MoveNext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// rarely used in practice&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Iterating Without &lt;code&gt;foreach&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Since &lt;code&gt;foreach&lt;/code&gt; is just syntactic shortcut, you can do the same manually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;enumerator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enumerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MoveNext&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;enumerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Custom Implementation Example
&lt;/h2&gt;

&lt;p&gt;You can also implement &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; yourself.&lt;br&gt;&lt;br&gt;
Here’s a simple example that generates even numbers up to a maximum value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EvenNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EvenNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_current&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;MoveNext&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;_current&lt;/span&gt; &lt;span class="p"&gt;+=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_current&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_current&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="n"&gt;Current&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Current&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;IEnumerator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;EvenNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IEnumerator&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IEnumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnumerator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;evens&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;EvenNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;evens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Output: 0, 2, 4, 6, 8, 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the &lt;code&gt;_current&lt;/code&gt; always starts in an invalid position and has the right value after the first call of &lt;code&gt;MoveNext()&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why is it Important?
&lt;/h2&gt;

&lt;p&gt;LINQ methods like &lt;code&gt;.Where()&lt;/code&gt;, &lt;code&gt;.Select()&lt;/code&gt;, and &lt;code&gt;.OrderBy()&lt;/code&gt; all extend &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Without it, LINQ wouldn’t exist.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;squared&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;squared&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Output: 1, 4, 9, 16, 25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Deferred Execution
&lt;/h2&gt;

&lt;p&gt;A powerful feature of &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; is &lt;strong&gt;deferred execution&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
LINQ queries aren’t run immediately, they’re only executed when you iterate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Nothing happens yet!&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Execution happens here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows efficient chaining of operations without unnecessary work.&lt;/p&gt;




&lt;h2&gt;
  
  
  Performance Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; only supports &lt;strong&gt;forward iteration&lt;/strong&gt;.
You can’t access items by index or know the count without iterating.
&lt;/li&gt;
&lt;li&gt;For random access or collection size, use &lt;code&gt;ICollection&amp;lt;T&amp;gt;&lt;/code&gt; or &lt;code&gt;IList&amp;lt;T&amp;gt;&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Best suited for &lt;strong&gt;streaming data&lt;/strong&gt; and &lt;strong&gt;large sequences&lt;/strong&gt; where you don’t want everything in memory at once.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; defines the contract for iteration in C#.
&lt;/li&gt;
&lt;li&gt;It powers &lt;code&gt;foreach&lt;/code&gt; and enables LINQ.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IEnumerator&amp;lt;T&amp;gt;&lt;/code&gt; drives iteration with &lt;code&gt;MoveNext()&lt;/code&gt; and &lt;code&gt;Current&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;LINQ queries on &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; use &lt;strong&gt;deferred execution&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;For advanced operations like indexing, prefer &lt;code&gt;IList&amp;lt;T&amp;gt;&lt;/code&gt; or &lt;code&gt;ICollection&amp;lt;T&amp;gt;&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;✅ That’s all, folks!  &lt;/p&gt;

&lt;p&gt;💬 &lt;strong&gt;Let’s Connect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <title>When I Went Blank in an Interview – and What I Learned About LINQ</title>
      <dc:creator>Renan Martins</dc:creator>
      <pubDate>Tue, 30 Sep 2025 14:30:00 +0000</pubDate>
      <link>https://dev.to/reenanms/when-i-went-blank-in-an-interview-and-what-i-learned-about-linq-41i5</link>
      <guid>https://dev.to/reenanms/when-i-went-blank-in-an-interview-and-what-i-learned-about-linq-41i5</guid>
      <description>&lt;p&gt;Recently, I had a job interview where I was asked a very simple question:&lt;br&gt;
&lt;strong&gt;“What is LINQ?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even though I know the answer, my mind just froze. For some reason, the only word that came to me was &lt;em&gt;“link”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After the interview, I laughed at myself — but it also inspired me to write this short article, not only to reinforce the concept for myself but also to help other beginners in .NET who might face the same question.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is LINQ in .NET?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;LINQ&lt;/strong&gt; stands for &lt;strong&gt;Language Integrated Query&lt;/strong&gt;.&lt;br&gt;
It is a feature of C# and .NET that allows developers to query and manipulate data in a consistent and expressive way, directly inside the programming language.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why is LINQ important?
&lt;/h3&gt;

&lt;p&gt;Before LINQ, working with different data sources (lists, XML, databases, etc.) required completely different approaches.&lt;br&gt;
LINQ simplifies this by providing &lt;strong&gt;a unified syntax&lt;/strong&gt; to query data, making code easier to read, write, and maintain.&lt;/p&gt;


&lt;h2&gt;
  
  
  A Simple Example
&lt;/h2&gt;

&lt;p&gt;Imagine you want to filter even numbers from a list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// LINQ query syntax&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;evens&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;
            &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
            &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;evens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Method syntax (more common in real-world projects, and also my preference):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;evens&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  More Usage Examples
&lt;/h2&gt;

&lt;p&gt;LINQ is not just about filtering. Here are some other powerful operators you’ll use often:&lt;/p&gt;

&lt;h3&gt;
  
  
  Count
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Any
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;hasEven&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Where
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;odds&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1, 3, 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OrderBy / OrderByDescending
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ordered&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;// 1, 2, 3, 4, 5, 6&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;desc&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6, 5, 4, 3, 2, 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Select
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;squares&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1, 4, 9, 16, 25, 36&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Combining Operators
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OrderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;$"Even number: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Where Can You Use LINQ?
&lt;/h2&gt;

&lt;p&gt;LINQ can be used in many contexts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;In-memory collections&lt;/strong&gt; (&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, etc.) → LINQ to Objects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Databases&lt;/strong&gt; (via Entity Framework) → LINQ to Entities&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;XML files&lt;/strong&gt; → LINQ to XML&lt;/li&gt;
&lt;li&gt;And more&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Upcoming Articles in This Series
&lt;/h2&gt;

&lt;p&gt;This article is just the beginning! I’ll be publishing more deep dives into how LINQ works under the hood and how we can even build our own LINQ-like library. Stay tuned for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When I Went Blank in an Interview – and What I Learned About LINQ&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/understanding-ienumerable-in-c-the-foundation-of-linq-5g6c"&gt;Understanding IEnumerable in C#: The Foundation of LINQ&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/how-extension-methods-unlock-linqs-magic-in-c-1jmd"&gt;How Extension Methods Unlock LINQ’s Magic in C#&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/cs-hidden-gem-how-yield-return-makes-iterators-simple-kno"&gt;C#’s Hidden Gem: How Yield Return Makes Iterators Simple&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/unit-testing-our-first-linq-like-methods-in-c-26jp"&gt;Unit Testing Our First LINQ-like Methods in C#&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://dev.to/reenanms/teaching-my-team-how-to-build-linq-from-scratch-11p9"&gt;Teaching My Team How to Build LINQ from Scratch&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;LINQ is one of the most powerful features in C#. It makes data querying &lt;strong&gt;integrated, type-safe, and expressive&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, if someone asks me again in an interview, I’ll have a much clearer answer ready — and hopefully no more blanks!&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Interview-ready answer:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;LINQ (Language Integrated Query) is a feature in .NET that provides a consistent and type-safe way to query and manipulate data from different sources (collections, databases, XML) directly within C#.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✅ That’s all, folks!&lt;/p&gt;




&lt;p&gt;💬 Let’s Connect&lt;/p&gt;

&lt;p&gt;Have any questions, suggestions for improvement, or just want to share your thoughts?&lt;br&gt;&lt;br&gt;
Feel free to leave a comment here, or get in touch with me directly on &lt;a href="https://www.linkedin.com/reenanms" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; — I’d love to connect!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>linq</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
