<?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: Francesco Girelli</title>
    <description>The latest articles on DEV Community by Francesco Girelli (@djremix6).</description>
    <link>https://dev.to/djremix6</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%2F785235%2F6d7387bc-f6ae-465c-8958-a9f7c0a9ab08.jpeg</url>
      <title>DEV Community: Francesco Girelli</title>
      <link>https://dev.to/djremix6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/djremix6"/>
    <language>en</language>
    <item>
      <title>C# Constants Management</title>
      <dc:creator>Francesco Girelli</dc:creator>
      <pubDate>Sun, 31 Jul 2022 11:59:00 +0000</pubDate>
      <link>https://dev.to/djremix6/c-constants-management-56do</link>
      <guid>https://dev.to/djremix6/c-constants-management-56do</guid>
      <description>&lt;p&gt;Hi devs!&lt;br&gt;
I'm a 22 yo dev and some days ago I looked out for the best practices to store and manage constants in a project. I found a guy on StackOverflow that said that you must create a static class with static methods that return the constant value, in that way you have all the constants inside one file and if you ever have to make a change you can easily find the constant... but I was thinking "If I want to be able to switch to debug constants or release constants without writing too much checks inside my code and have a strong consistency, how can I make it based on this 'best practice'?" so I wrote this, it works but i wanted to know from more expert dotnet and C# devs if it is a good way to do that or not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class ConstantsBase 
{
    public static ConstantsBase Instance {get; set;}
    protected ConstantsBase() {}

    public abstract string GetSomeValue();
}

public class ConstantsA : ConstantsBase
{
    public override string GetSomeValue()
    {
        return "SomeValue";
    }
}

public class ConstantsB : ConstantsBase
{
    public override string GetSomeValue()
    {
        return "SomeOtherValue";
    }
}

public class Program 
{
    public static void Main()
    {
        #if DEBUG
        ConstantsBase.Instance = new ConstantsA();
        #elif RELEASE
        ConstantsBase.Instance = new ConstantsB();
        #endif

        Console.WriteLine(ConstantsBase.Instance.GetSomeValue());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I designed it as a singleton so it can be called from anywhere inside the program without being instantiated.&lt;/p&gt;

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