Skip to content

Instantly share code, notes, and snippets.

@BanksySan
Last active May 5, 2020 19:31
Show Gist options
  • Save BanksySan/b7f0b19d20c0cbd76ffcd3e722b6da5d to your computer and use it in GitHub Desktop.
Save BanksySan/b7f0b19d20c0cbd76ffcd3e722b6da5d to your computer and use it in GitHub Desktop.
Blog: Public Consts Are Bad (5)
using static System.Console;
using System;
public static class Constants
{
private const double PI = 3.14;
public static double PI_1 = PI;
public static readonly double PI_2 = PI;
public static double PI_3 {get;} = PI;
public static double PI_4 = PI;
public static double PI_5 => PI;
public static double GetPi()
{
return PI;
}
}
public static class Program
{
private static void Main()
{
WriteLine($"π 1 = {Constants.PI_1}");
WriteLine($"π 2 = {Constants.PI_2}");
WriteLine($"π 3 = {Constants.PI_3}");
WriteLine($"π 4 = {Constants.PI_4}");
WriteLine($"π 5 = {Constants.PI_5}");
WriteLine($"GetPi() = {Constants.GetPi()}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment