<?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: Salah</title>
    <description>The latest articles on DEV Community by Salah (@frqsalah).</description>
    <link>https://dev.to/frqsalah</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%2F86752%2F4f45f1da-c898-400b-89ac-471ea9fc32ba.jpeg</url>
      <title>DEV Community: Salah</title>
      <link>https://dev.to/frqsalah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frqsalah"/>
    <language>en</language>
    <item>
      <title>Don't use IA only to code faster</title>
      <dc:creator>Salah</dc:creator>
      <pubDate>Mon, 09 Mar 2026 10:33:57 +0000</pubDate>
      <link>https://dev.to/frqsalah/dont-use-ia-only-to-code-faster-45df</link>
      <guid>https://dev.to/frqsalah/dont-use-ia-only-to-code-faster-45df</guid>
      <description>&lt;p&gt;&lt;strong&gt;Most .NET developers use AI to write code faster. The ones moving ahead use it to design better.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In my experience, writing the actual C# logic is rarely the bottleneck. The real delays on a project happen in the "gaps" between coding.&lt;/p&gt;

&lt;p&gt;Here is where the time actually goes:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Setup (The "File &amp;gt; New" Tax)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Spending 2 hours configuring a new Microservice or Web API.&lt;/li&gt;
&lt;li&gt;Setting up Dependency Injection.&lt;/li&gt;
&lt;li&gt;Adding Middleware and Logging.&lt;/li&gt;
&lt;li&gt;Configuring Docker and CI/CD pipelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The AI Fix:&lt;/strong&gt; Use custom "System Prompts" to generate a full .NET 9 skeleton that follows your team's specific standards in seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Wait (The PR Black Hole)
&lt;/h3&gt;

&lt;p&gt;Sending a Pull Request and waiting 3 days for a reviewer to catch a simple syntax error or a naming convention mistake.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The AI Fix:&lt;/strong&gt; Run an LLM-based "Pre-Review" on your own branch. It can catch the "obvious" mistakes before a human even sees them. This keeps your Senior Devs focused on logic, not typos.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Missing Docs (The "Legacy" Trap)
&lt;/h3&gt;

&lt;p&gt;Shipping a feature with zero documentation. The next developer (or you, 6 months from now) spends a day just trying to understand the data flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The AI Fix:&lt;/strong&gt; Feed your final classes into an AI to generate a Markdown README or a Mermaid.js sequence diagram. It’s a 30-second task that saves hours of future debugging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Hard Truth:&lt;/strong&gt;&lt;br&gt;
If you only use GitHub Copilot to autocomplete a foreach loop, you are only fixing 20% of the problem.&lt;/p&gt;

&lt;p&gt;The real "Senior" move is using AI to automate the friction, so you can spend your energy on Architecture.&lt;/p&gt;

&lt;p&gt;Where does your dev day feel the most wasteful? For me, it’s always the repetitive setup of new services.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>architecture</category>
      <category>ai</category>
    </item>
    <item>
      <title>What I Built: The "Claude Code" of Finance</title>
      <dc:creator>Salah</dc:creator>
      <pubDate>Mon, 02 Mar 2026 15:02:00 +0000</pubDate>
      <link>https://dev.to/frqsalah/what-i-built-the-claude-code-of-finance-3794</link>
      <guid>https://dev.to/frqsalah/what-i-built-the-claude-code-of-finance-3794</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/mlh/built-with-google-gemini-02-25-26"&gt;Built with Google Gemini: Writing Challenge&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;FinAgent.NET&lt;/strong&gt;, an &lt;em&gt;autonomous financial research agent&lt;/em&gt;. The goal was simple yet ambitious: create a tool that doesn't just "chat," but thinks, plans, and learns while investigating market data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;: Financial research is often fragmented. Analysts jump between news terminals, stock price APIs, and SEC filings. It’s manual, slow, and prone to oversight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;: FinAgent.NET acts as a digital quantitative analyst. You give it a complex prompt "Analyze the impact of interest rate changes on tech stocks over the last quarter" and it handles the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI's Role&lt;/strong&gt;: Using the Microsoft Agent Framework and Google Gemini via Microsoft.Extensions.AI, the AI operates in a Self-Correction Loop. It creates a plan, executes tool calls to fetch real-time market data, and then reflects on its own findings. If the data is incomplete, it goes back into the loop until the research is solid.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 What I Built: The "Claude Code" of Finance
&lt;/h2&gt;

&lt;p&gt;I built FinAgent.NET, an autonomous financial research agent. The goal was simple yet ambitious: create a tool that doesn't just "chat," but thinks, plans, and learns while investigating market data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; Financial research is often fragmented. Analysts jump between news terminals, stock price APIs, and SEC filings. It’s manual, slow, and prone to oversight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt; FinAgent.NET acts as a digital quantitative analyst. You give it a complex prompt—"Analyze the impact of interest rate changes on tech stocks over the last quarter"—and it handles the rest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI's Role:&lt;/strong&gt; Using the Microsoft Agent Framework and Google Gemini via Microsoft.Extensions.AI, the AI operates in a Self-Correction Loop. It creates a plan, executes tool calls to fetch real-time market data, and then reflects on its own findings. If the data is incomplete, it goes back into the loop until the research is solid.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 What I Learned: Beyond the Code
&lt;/h2&gt;

&lt;p&gt;Building this project wasn't just about syntax; it was about architectural philosophy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agnosticism is Power:&lt;/strong&gt; By using Microsoft.Extensions.AI, I learned how to build a system that is model-agnostic. Switching from a cloud-based LLM to a local model via Ollama became a configuration change rather than a code rewrite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Single Agent" Realization:&lt;/strong&gt; One of the biggest technical pivots was moving away from a complex multi-agent system (three separate agents talking) to a Single Agent State Machine. I realized that for a research loop, keeping the context in a single, well-managed ChatHistory is significantly cleaner and more reliable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Soft Skills in "AI Negotiation":&lt;/strong&gt; I learned how to treat the AI as a collaborator. Correcting the AI's initial over-engineered design for the agent loop taught me that a builder's intuition is still the ultimate compass.&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 Google Gemini Feedback: The Good, The Bad, and The Ugly
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Good
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Contextual Speed:&lt;/strong&gt; Gemini was incredibly fast at parsing the GitHub repositories for examples and translating those Python concepts into a .NET-friendly architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure:&lt;/strong&gt; The ability to generate complex, ready-to-use plan.md files for other AI dev tools (like Cursor or Cline) acted as a massive force multiplier.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bad
&lt;/h3&gt;

&lt;p&gt;Framework Friction: Occasionally, the AI leaned toward older Semantic Kernel patterns when I explicitly asked for the newer Microsoft Agent Framework. It required a few "pokes" to stay updated with the latest documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Ugly
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Architectural Hallucinations:&lt;/strong&gt; In the beginning, Gemini pushed for a "Group Chat" multi-agent design because that's a common framework trope. It took a firm human intervention to realize that for this specific use case, a single-loop design was superior. It’s a reminder that AI is a co-pilot, not the captain.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Where I’m Headed Next
&lt;/h2&gt;

&lt;p&gt;The foundation of FinAgent.NET is solid. My next steps involve:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-time Streaming:&lt;/strong&gt; Implementing SignalR to stream the agent's "thoughts" to a dashboard in real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Persistent Memory:&lt;/strong&gt; Giving the agent a vector database so it "remembers" previous market analyses to improve its future planning.&lt;/p&gt;

&lt;p&gt;FinAgent.NET is proof that with the right tools and a bit of grit, we can build C# systems that don't just process data—they understand it.&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>ai</category>
      <category>hackathon</category>
    </item>
    <item>
      <title>C# Optimizations That Boosted Our Application's Performance</title>
      <dc:creator>Salah</dc:creator>
      <pubDate>Tue, 26 Nov 2024 11:16:09 +0000</pubDate>
      <link>https://dev.to/frqsalah/c-optimizations-that-boosted-our-applications-performance-1bm1</link>
      <guid>https://dev.to/frqsalah/c-optimizations-that-boosted-our-applications-performance-1bm1</guid>
      <description>&lt;p&gt;In the world of software development, performance is often the difference between success and failure. As an experienced developer, I faced a significant challenge when our C# application began to struggle under heavy load. After debugging and optimization, my team and I managed to give a good boost to the application's performance. &lt;br&gt;
In this article, I'll share some easy key optimizations that made this possible, along with some practical examples and explanations.&lt;/p&gt;
&lt;h2&gt;
  
  
  Choosing the Right Data Structures
&lt;/h2&gt;

&lt;p&gt;One of the most significant performance bottlenecks in any application is the choice of data structures. In C#, the right data structure can make all the difference. In some high-performance critical scenarios we can for example use Span&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Using Span Instead of Arrays
&lt;/h3&gt;

&lt;p&gt;Before&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;ProcessData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&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;i&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;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&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;++)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Process each byte&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;After&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;ProcessData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Span&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;data&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;byte&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Process each byte&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;Span is a stack-allocated struct that provides a memory-safe way to work with contiguous blocks of data (Span is not supposed to replace arrays).&lt;br&gt;
By avoiding the overhead of array bounds checking and unnecessary memory allocations, Span can significantly improve performance, especially in tight loops.&lt;/p&gt;
&lt;h2&gt;
  
  
  Minimizing Garbage Collection Pressure
&lt;/h2&gt;

&lt;p&gt;Garbage collection (GC) is a powerful feature of .NET, but it can introduce significant overhead if not managed properly. In some scenarios when the class is expensive to create or destroy, we can create an object pool by using a ConcurrentBag.&lt;br&gt;
Example: Object Pooling&lt;/p&gt;

&lt;p&gt;Before:&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;ProcessMessages&lt;/span&gt;&lt;span class="p"&gt;()&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="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="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&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;Message&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Process message&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;After:&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;ProcessMessages&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;pool&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;ObjectPool&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Message&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="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="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Process message&lt;/span&gt;
        &lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;In C# Object Pooling reuses objects instead of creating new ones, reducing the frequency of garbage collection.&lt;br&gt;
We avoid the overhead of constant allocations and deallocations by reusing Message objects.&lt;/p&gt;
&lt;h2&gt;
  
  
  Algorithmic Optimizations
&lt;/h2&gt;

&lt;p&gt;Sometimes, the biggest performance gains come from rethinking your algorithms. &lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Replacing Linear Search with Binary Search
&lt;/h3&gt;

&lt;p&gt;Before:&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="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Contains&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;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;value&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="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;value&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;After:&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="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;Contains&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;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&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;.&lt;/span&gt;&lt;span class="nf"&gt;Sort&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;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BinarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;&amp;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;List.BinarySearch(T) Method uses a binary search algorithm to locate a specific element in the sorted List or a portion of it.&lt;br&gt;
Binary Search has a time complexity of O(log n), whereas linear search is O(n).&lt;br&gt;
By sorting the list once and using binary search, we significantly reduce the time complexity for multiple searches.&lt;/p&gt;
&lt;h2&gt;
  
  
  Leveraging Parallel Processing
&lt;/h2&gt;

&lt;p&gt;Modern CPUs have multiple cores, and C# provides powerful tools to take advantage of them.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Parallel LINQ (PLINQ)
&lt;/h3&gt;

&lt;p&gt;Before:&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;results&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&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="nf"&gt;Process&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="nf"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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;results&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AsParallel&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="nf"&gt;Process&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="nf"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;PLINQ automatically parallelizes LINQ queries, distributing the workload across multiple cores.&lt;br&gt;
This can lead to significant performance improvements for CPU-bound operations.&lt;/p&gt;
&lt;h2&gt;
  
  
  Caching and Avoiding Redundant Computations
&lt;/h2&gt;

&lt;p&gt;Caching is a powerful technique to avoid redundant computations.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Memoization with Dictionary Cache
&lt;/h3&gt;

&lt;p&gt;Before:&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="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;Fibonacci&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;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;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;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;1&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;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Fibonacci&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;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;Fibonacci&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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;private&lt;/span&gt; &lt;span class="n"&gt;Dictionary&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;,&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;cache&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;Dictionary&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;,&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;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;Fibonacci&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;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;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;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;1&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;n&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;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ContainsKey&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cache&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="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="nf"&gt;Fibonacci&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;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;Fibonacci&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="n"&gt;cache&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="n"&gt;result&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;Memoization stores the results of expensive function calls and returns the cached result when the same inputs occur again.&lt;br&gt;
By caching Fibonacci numbers, we reduce the time complexity from exponential to linear.&lt;/p&gt;
&lt;h2&gt;
  
  
  Avoiding Unnecessary I/O Operations
&lt;/h2&gt;

&lt;p&gt;I/O operations, such as file access or network calls, are often the biggest bottlenecks in an application.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Minimizing Database Calls
&lt;/h3&gt;

&lt;p&gt;Before:&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;for&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;i&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;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&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;++)&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;user&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;GetUserFromDatabase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ids&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;]);&lt;/span&gt;
    &lt;span class="c1"&gt;// Process user&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&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;users&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;GetUsersFromDatabase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ids&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;user&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Process user&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;Batching database calls reduces the number of round trips to the database, significantly improving performance.&lt;br&gt;
By fetching all users in a single call, we minimize the I/O overhead.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Structs Instead of Classes for Small Data Types
&lt;/h2&gt;

&lt;p&gt;Value types (structs) are stored on the stack, which can be more efficient than reference types (classes) stored on the heap.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Using Structs for Small Data
&lt;/h3&gt;

&lt;p&gt;Before:&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;Point&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;int&lt;/span&gt; &lt;span class="n"&gt;X&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="k"&gt;set&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="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Y&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="k"&gt;set&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;After:&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;struct&lt;/span&gt; &lt;span class="nc"&gt;Point&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;int&lt;/span&gt; &lt;span class="n"&gt;X&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;int&lt;/span&gt; &lt;span class="n"&gt;Y&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;Structs are value types and are allocated on the stack, which is faster and uses less memory for small data types.&lt;br&gt;
By converting Point to a struct, we reduce the overhead of object creation and garbage collection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Profiling and Benchmarking
&lt;/h2&gt;

&lt;p&gt;Before making any optimizations, it's crucial to identify the actual bottlenecks in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Using Benchmark.NET
&lt;/h3&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;MemoryDiagnoser&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;MyBenchmarks&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Benchmark&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;MyMethod&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Code to be benchmarked&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;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;Benchmark.NET is a powerful tool for measuring the performance of your code.&lt;br&gt;
By diagnosing memory usage and execution time, you can pinpoint the areas that need optimization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As a developer, you can boost the performance of your C# application by applying the right strategies. In this article, I explained how it's important to always try to choose the right data structure, to use wisely parallel processing, and to avoid doing redundant computations. Optimization is not just about making code run faster, it's about making intelligent decisions that balance performance, readability, and maintainability.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>performance</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
