<?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: Russell Nguyen</title>
    <description>The latest articles on DEV Community by Russell Nguyen (@russellntanh).</description>
    <link>https://dev.to/russellntanh</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%2F2133922%2F768acd08-83ab-4307-937b-7823660effec.png</url>
      <title>DEV Community: Russell Nguyen</title>
      <link>https://dev.to/russellntanh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/russellntanh"/>
    <language>en</language>
    <item>
      <title>Pattern Matching</title>
      <dc:creator>Russell Nguyen</dc:creator>
      <pubDate>Sun, 06 Oct 2024 00:48:26 +0000</pubDate>
      <link>https://dev.to/russellntanh/pattern-matching-2ibo</link>
      <guid>https://dev.to/russellntanh/pattern-matching-2ibo</guid>
      <description>&lt;p&gt;Pattern Matching is an important feature from C# 7.&lt;br&gt;
Here is an example to show how i can be used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;internal class Program
{
    static void Main(string[] args)
    {
        Rectangle rectangle = new Rectangle(5.0, 5.0);
        Circle circle = new Circle(5.0);
        Square square = new Square(5.0);

        var a1 = Area(rectangle);

        var a2 = Area(circle);

        var a3 = Area(square);
    }

    public static double Area (object shape)
    {
        if (shape is Rectangle r) return r.Width * r.Height;
        if (shape is Circle c) return c.Radius*2*Math.PI;
        if (shape is Square s) return s.Length*s.Length;
        return double.NaN;
    }
}

public class Rectangle
{
    public double Width { get; set; }
    public double Height { get; set; }

    public Rectangle(double width, double height)
    {
        Width = width;
        Height = height;
    }
}

public class Circle
{
    public double Radius {  get; set; }

    public Circle(double radius)
    {
        Radius = radius;
    }
}

public class Square
{
    public double Length { get; set; }

    public Square(double length)
    {
        Length = length;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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