<?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: .Net Trends</title>
    <description>The latest articles on DEV Community by .Net Trends (@dotnettrends).</description>
    <link>https://dev.to/dotnettrends</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%2F1401192%2Fc0fc9dbc-55b1-4071-9947-ba360af21e8f.jpg</url>
      <title>DEV Community: .Net Trends</title>
      <link>https://dev.to/dotnettrends</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dotnettrends"/>
    <language>en</language>
    <item>
      <title>Type Unions for C# (aka discriminated unions)</title>
      <dc:creator>.Net Trends</dc:creator>
      <pubDate>Sun, 28 Jul 2024 14:49:01 +0000</pubDate>
      <link>https://dev.to/dotnettrends/type-unions-for-c-aka-discriminated-unions-ee4</link>
      <guid>https://dev.to/dotnettrends/type-unions-for-c-aka-discriminated-unions-ee4</guid>
      <description>&lt;p&gt;A long-desired feature in C# is now proposed in the C# community. Type Unions (aka discriminated unions) are specified in a new proposal of the language committee's official C# language repository. This proposal aims to bring a new level of flexibility and type safety to C#, enabling developers to write more expressive and resilient code.&lt;br&gt;
Type Unions will probably be added in one of the next releases after C# 13, which is nearly complete and shipping in November 2024.&lt;/p&gt;

&lt;p&gt;More details: &lt;a href="https://dotnetrends.net/type-unions-discriminated.html" rel="noopener noreferrer"&gt;https://dotnetrends.net/type-unions-discriminated.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>New LINQ methods coming in .NET 9</title>
      <dc:creator>.Net Trends</dc:creator>
      <pubDate>Sat, 27 Jul 2024 10:57:31 +0000</pubDate>
      <link>https://dev.to/dotnettrends/new-linq-methods-coming-in-net-9-1hce</link>
      <guid>https://dev.to/dotnettrends/new-linq-methods-coming-in-net-9-1hce</guid>
      <description>&lt;p&gt;&lt;strong&gt;CountBy&lt;/strong&gt;&lt;br&gt;
This is a pretty and very useful method and it is better explained with an example:&lt;/p&gt;

&lt;p&gt;Before .NET 9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var roleCounts = users.GroupBy(user =&amp;gt; user.Role) // Group users by their roles
    .Select(group =&amp;gt; new { Role = group.Key, Count = group.Count() });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With .NET 9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
var roleCounts = users.CountBy(user =&amp;gt; user.Role);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AggregateBy&lt;/strong&gt;&lt;br&gt;
Use this new method instead of GroupBy to make the syntax clearer:&lt;br&gt;
Before .NET 9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var levelSumByRole = users.GroupBy(user =&amp;gt; user.Role)
    .Select(group =&amp;gt; new { Role = group.Key, 
        SumByLevel = group.Sum(user =&amp;gt; user.Level) });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With .NET 9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var levelSumByRole = users.AggregateBy(
    user =&amp;gt; user.Role,
    seed: 0,
    (currentTotal, user) =&amp;gt; currentTotal + user.AccessLevel);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Index&lt;/strong&gt;&lt;br&gt;
More convenient Linq method for getting value and index. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach (var (index, item) in people.Index())
{
    Console.WriteLine($"Entry {index}: {item}");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same can be achieved before .NET 9 with a more complex syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach (var (item, index) in people.Select((item, index) =&amp;gt; (item, index)))
{
    Console.WriteLine($"Entry {index}: {item}");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the item and index are reversed with the Index method.&lt;/p&gt;

&lt;p&gt;More: &lt;a href="https://dotnetrends.net/new-linq-methods.html" rel="noopener noreferrer"&gt;https://dotnetrends.net/new-linq-methods.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>programming</category>
    </item>
    <item>
      <title>This new Task.WhenEach API</title>
      <dc:creator>.Net Trends</dc:creator>
      <pubDate>Mon, 01 Apr 2024 18:15:51 +0000</pubDate>
      <link>https://dev.to/dotnettrends/this-new-wheneach-api-in-c-9-3mop</link>
      <guid>https://dev.to/dotnettrends/this-new-wheneach-api-in-c-9-3mop</guid>
      <description>&lt;p&gt;This new WhenEach API is 🔥. Really shows true composability of C#. No more complex WhenAny loops!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/HWP804iXXF"&gt;https://t.co/HWP804iXXF&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Writing async/await from scratch in C# with Stephen Toub</title>
      <dc:creator>.Net Trends</dc:creator>
      <pubDate>Mon, 01 Apr 2024 17:46:17 +0000</pubDate>
      <link>https://dev.to/dotnettrends/writing-asyncawait-from-scratch-in-c-with-stephen-toub-56fh</link>
      <guid>https://dev.to/dotnettrends/writing-asyncawait-from-scratch-in-c-with-stephen-toub-56fh</guid>
      <description>&lt;p&gt;Demystify the world of asynchronous programming with .NET and specifically the magic behind async/await,  learn from the best&lt;/p&gt;

&lt;p&gt;&lt;a href="https://t.co/G3e7h2vZLL"&gt;https://t.co/G3e7h2vZLL&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
