<?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: Ulisses Cavalcante</title>
    <description>The latest articles on DEV Community by Ulisses Cavalcante (@ucavalcante).</description>
    <link>https://dev.to/ucavalcante</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%2F187107%2Ff1b708e4-018d-4b8e-a8f8-347844fd5a75.jpeg</url>
      <title>DEV Community: Ulisses Cavalcante</title>
      <link>https://dev.to/ucavalcante</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ucavalcante"/>
    <language>en</language>
    <item>
      <title>The default value to a property ins't really default</title>
      <dc:creator>Ulisses Cavalcante</dc:creator>
      <pubDate>Wed, 28 Jul 2021 01:13:13 +0000</pubDate>
      <link>https://dev.to/ucavalcante/the-default-value-to-a-property-ins-t-really-default-27n5</link>
      <guid>https://dev.to/ucavalcante/the-default-value-to-a-property-ins-t-really-default-27n5</guid>
      <description>&lt;p&gt;I was trying to do a simple and easy-to-use validation for a class today, and I came across this situation&lt;/p&gt;

&lt;p&gt;First I wrote this class using a property and added there a default value like this &lt;code&gt;public int Age { get; set; } = 18&lt;/code&gt;, and I thought already that this property has a default value, and if I compare this instance with &lt;code&gt;default(T)&lt;/code&gt;, will I have a simple validator?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g2nooss9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mk0tp8to5oaqwdfwa6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g2nooss9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mk0tp8to5oaqwdfwa6m.png" alt="Code Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the answer is NO, I know there are some great projects like &lt;a href="https://www.nuget.org/packages/Flunt/"&gt;Flunt&lt;/a&gt; or &lt;a href="https://www.nuget.org/packages/FluentValidation"&gt;FluentValidation&lt;/a&gt;, but I thought of a simple comparator with the default values, and what I've seen is that actually the &lt;code&gt;=18&lt;/code&gt; is actually just an assignment that occurs during the moment the class is instantiated, but that when declaring the &lt;code&gt;default(T)&lt;/code&gt; value it doesn't actually do any attribution declaring only as null.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iGgIIMi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6kex499oa9robgrnm03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iGgIIMi8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6kex499oa9robgrnm03.png" alt="Code Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see in previous image, the &lt;code&gt;default(T)&lt;/code&gt; return a &lt;code&gt;null&lt;/code&gt; value for a reference type like my example class and for a value type this will return &lt;code&gt;0&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;For finish this is definition from (docs) [&lt;a href="https://docs.microsoft.com/en-us/dotnet/csharp/properties"&gt;https://docs.microsoft.com/en-us/dotnet/csharp/properties&lt;/a&gt;] for an default property.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xv67djQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo0h0p2whre3mgb7hjrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xv67djQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo0h0p2whre3mgb7hjrw.png" alt="docs.com definition for properties"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if by chance you know any easy way to validate please contribute to the comments below, thanks for reading.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>vscode</category>
    </item>
    <item>
      <title>C# lambda vs foreach readability.</title>
      <dc:creator>Ulisses Cavalcante</dc:creator>
      <pubDate>Wed, 30 Jun 2021 05:23:25 +0000</pubDate>
      <link>https://dev.to/ucavalcante/c-lambda-vs-foreach-readability-4cpg</link>
      <guid>https://dev.to/ucavalcante/c-lambda-vs-foreach-readability-4cpg</guid>
      <description>&lt;p&gt;Hey guys, recently a receive an feedback that i need to change my code, turn an lambda expression into a foreach loop because its more adherent to clean code, i create this example to explain.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zqOwbqjA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3z1y6sgu6xvykpdvqyk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zqOwbqjA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3z1y6sgu6xvykpdvqyk.png" alt="Overall code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The both versions give me same results, but in my opinion this lambda expression is easy to understand, and easy to write and maintain, and i like to use that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i48cKLT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fesbm1zhx6qrz7hb3kg7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i48cKLT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fesbm1zhx6qrz7hb3kg7.png" alt="lambdaExample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;i receive an recommendation to change that to a for-each loop, like this, to be more clean code adherent.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E_DWWqAp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xabtiotgtyeh46khqs37.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E_DWWqAp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xabtiotgtyeh46khqs37.png" alt="foreach"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I really want see other people opinions and arguments about this, and i like lambda expression for me they are very powerful and easy to use.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>cleancode</category>
      <category>help</category>
    </item>
  </channel>
</rss>
