You can try this:
public class Constants { public Dictionary<String, Double> constants = new Dictionary<String, Double>(); public void SetPi() => constants.Add("PI", Math.PI); } public class Program { private static void Main(String[] args) { Constants constant = new Constants(); constant.SetPi(); Console.WriteLine(constant.constants["PI"]); Console.ReadKey(); } }
Given the comments @ tym32167, you can do this:
public class Constants { public static Dictionary<String, Double> constants = new Dictionary<String, Double> { { "PI", Math.PI } }; } public class Program { private static void Main(String[] args) { Console.WriteLine(Constants.constants["PI"]); Console.ReadKey(); } }
Starting from C # 6.0, another initialization method is also available:
public class Constants { public static Dictionary<String, Double> constants = new Dictionary<String, Double> { ["PI"] = Math.PI }; }