<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Stock on Medium]]></title>
        <description><![CDATA[Stories by Daniel Stock on Medium]]></description>
        <link>https://medium.com/@danielcunhastock?source=rss-dd334904e06e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dRRbNa-Cz1mZkpAJePciwQ@2x.jpeg</url>
            <title>Stories by Daniel Stock on Medium</title>
            <link>https://medium.com/@danielcunhastock?source=rss-dd334904e06e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:31:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielcunhastock/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Elevating Efficiency: Discovering C# 12’s Collection Expressions]]></title>
            <link>https://medium.com/@danielcunhastock/elevating-efficiency-discovering-c-12s-collection-expressions-0016e87e199a?source=rss-dd334904e06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0016e87e199a</guid>
            <category><![CDATA[net8]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[csharp-programming]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Daniel Stock]]></dc:creator>
            <pubDate>Mon, 18 Mar 2024 12:02:23 GMT</pubDate>
            <atom:updated>2024-03-18T12:02:23.296Z</atom:updated>
            <content:encoded><![CDATA[<p>The current approaches in the C# Programming Language were very verbose. In other programming languages, like Python for instance, collections are handled in a more convenient and pleasant way. Having a literal form allows for maximum flexibility from the compiler implementation to optimize the literal to produce at least as good a result as a user could provide, but with simpler code.</p><p>Enough talking, let’s see how it can help us in our daily routines.</p><p>Let’s recap how to create a collection list. In this example, we’re going to work with an array and a list of integers.</p><pre>int[] bookIdsA = {1001, 1002, 1003, 1004};<br>var bookIdsB = new List&lt;int&gt; {1011, 1012, 1013, 1014};</pre><p>Using collection expressions feature, you can create collections in an easier way and manage them easily. In order to use collection expressions, replace the `{}` with `[]` when populating the collection. The same example we had above would look like this:</p><pre>int[] bookIdsA = [1001, 1002, 1003, 1004];<br>List&lt;int&gt; bookIdsB = [1011, 1012, 1013, 1014];</pre><p>Even (n)D arrays are embraced with Collection Expressions.</p><pre>int[][] sectors = [bookIdsA, bookIdsB];</pre><p>Collection expressions have introduced the spread operator too (..). The spread operator, .. in a collection expression replaces its argument with the elements from that collection. The argument must be a collection type. The following examples show how the spread operator works:</p><pre>WriteCollectionElements(bookIdsA);<br>WriteCollectionElements([.. bookIdsA, .. bookIdsB, .. bookIdsC]);<br><br>public static void WriteCollectionElements(int[] collection){<br>    foreach (var element in collection)<br>    {<br>        Console.Write($&quot;{element} &quot;);<br>    }<br>    Console.WriteLine(&quot;&quot;);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*564iIwSrag7sbIHCM-ViEQ.gif" /></figure><p>You can use collection expressions anywhere you need a collection of elements. They can specify the initial value for a collection or be passed as arguments to methods that take collection types. You can learn more about collection expressions in the language reference article on collection expressions or the feature specification.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0016e87e199a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deep dive into .NET 8 Constructor Parameters]]></title>
            <link>https://medium.com/@danielcunhastock/a-deep-dive-into-net-8-constructor-parameters-0f3e75a9e62e?source=rss-dd334904e06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f3e75a9e62e</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[net8]]></category>
            <dc:creator><![CDATA[Daniel Stock]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 01:32:16 GMT</pubDate>
            <atom:updated>2024-03-12T01:32:16.488Z</atom:updated>
            <content:encoded><![CDATA[<h3>A deep dive into .NET 8 Constructor Parameters</h3><p>For those already familiar with records or structs in previous versions, the concept of primary constructors isn’t entirely new. Introduced in earlier iterations of C#, primary constructors have been a staple for developers utilizing these constructs. They provide a streamlined approach to initializing objects, enhancing code clarity and conciseness. With their inclusion, C# reinforces its commitment to offering efficient and intuitive solutions for developers, ensuring smoother and more expressive code bases.</p><p>With .NET 8, C# 12 extends primary constructors to classes, expanding their utility beyond records and structs. While they offer a convenient means to initialize class objects, developers must grasp the nuances to avoid misinterpretation and potential pitfalls. Mastery of these details ensures effective utilization of this feature, enhancing code readability and maintainability while minimizing errors.</p><p>To get started, let’s take a look at what it looks like:</p><pre>public class Book(int id, string title, string author)<br><br>var book = new Book(8091, &quot;Clean Code&quot;, &quot;Robert C. Martin&quot;);</pre><p>One notable benefit is its prevention of the compiler from declaring an implicit parameterless constructor, providing more control over the initialization process. Additionally, primary constructors eliminate the need for separate constructor definitions, streamlining code and reducing redundancy.</p><p>It’s crucial to recognize that in records, constructor parameters were treated as properties, enabling easy access and manipulation. However, in classes, these parameters are handled differently; they are considered as private attributes, limiting their accessibility from outside the class. Despite this limitation, they can still be modified within the class since they are not declared as readonly. This differentiation underscores the nuanced behavior of constructor parameters across different types in C#.</p><p>While constructor parameters are inherently private, it’s important to note that this doesn’t limit you from adjusting their accessibility. You can still declare public attributes within the constructor scope, granting you the flexibility to manage attributes according to your needs.</p><pre>public class Book(int id, string title, string writer){<br>  public int Id { get; } = id;<br>  public string Title { get; } = title;<br>  public string Writer { get; } = writer;<br>  public override string ToString() =&gt; $&quot;{Id} - {Writer}&#39;s {Title}&quot;;<br>}</pre><p>Also you can define a parameterless constructor, you have to use the `this` declaration to instantiate the inner variables:</p><pre>public class Book(int id, string title, string writer){<br>    public int Id { get; } = id;<br>    public string Title { get; } = title;<br>    public string Writer { get; } = writer;<br>    public override string ToString() =&gt; $&quot;{Id} - {Writer}&#39;s {Title}&quot;;<br><br>    public Book() : this(1, &quot;&quot;, &quot;&quot;);<br>}</pre><p>In coding, parameter constructors serve as a valuable tool for enhancing code readability and minimizing errors stemming from missing or disordered parameters. By utilizing parameter constructors, developers can succinctly define and initialize class properties, streamlining the instantiation process and making code more intuitive to follow. These constructors provide a clear blueprint for how objects should be created, facilitating better organization and maintenance of codebases. To delve deeper into this topic and explore the benefits of parameter constructors, consider visiting the Microsoft documentation on C# 12 updates at <a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12#primary-constructors.">https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12#primary-constructors.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f3e75a9e62e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>