开发者

Single file/class to store constants in ASP.NET

开发者 https://www.devze.com 2022-12-09 06:54 出处:网络
I have a ASP.NET web application which has more than 100 pages. Each page is using some commo开发者_JAVA技巧n values ( ex : current USDoller rate) .This can be changed at any time. Now I want to maint

I have a ASP.NET web application which has more than 100 pages. Each page is using some commo开发者_JAVA技巧n values ( ex : current USDoller rate) .This can be changed at any time. Now I want to maintain this value in a single file so that i can change only her at any time to get it reflected throughtout the project.I dont want to store it in web config. I want to store it in some other place

Any thoughts ?


Make a static class like this:

public static class MyConsts {
   public const string Prefix = "n-";
}

From anywhere in your project use:

MyConsts.Prefix

(Note: const is implicitly static)


My initial thoughts are one of the following:

  1. Store it in a database table and create a mechanism for editing the values
  2. Create a static class and store them there


Why not just make a static class and store the constants there. That way when you change it, everything will get the new values.

0

精彩评论

暂无评论...
验证码 换一张
取 消