How to Write Constants Containing Multiple Values in C# Console App? -
let's wanted create constant return exchange fees me double
in c#. here in javascript:
var exchangefees = { fidelity: .25, etrade: .2, scotttrade: .15 }
this way, can import , have work sort of enum: exchangefees.fidelity
me fee need, , clear. in typescript, bit less rational:
//i realized static class after typed export class exchangefees { fidelity: number; etrade: number; scotttrade: number; constructor() { this.fidelity= .25; this.etrade= .2; this.scotttrade = .15; } } export const exchangefees : exchangefees = new exchangefees ();
this seems hacky-as-hell, javascript, whatchu gonna do, etc. seems hacky in c# though, create static class , put in constants.cs
file so? there better way?
public static class exchangefess { public static double fidelity = .25; public static double etrade = .2; public static double scotttrade = .15; }
i read answer here, should put in appsettings
somehow or there no point?
i realize 101 question, not sure approaching cleanly.
what have fine. alternative write:
public sealed class exchangefess { public const double fidelity = .25; public const double etrade = .2; public const double scotttrade = .15; }
in order have field constant. however, comes drawbacks of own, see here.
however, values don't seem constant, , shouldn't baked code. should use type of configuration system. appsettings does provide functionality, me doesn't seem correct place put it. i'd have configuration file or database application reads @ start up.
then, use code is, replace hard coded values (optionally cached) lookup configuration.
Comments
Post a Comment