Shyju
Shyju

Reputation: 218962

Single file/class to store constants in ASP.NET

I have a ASP.NET web application which has more than 100 pages. Each page is using some common 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 ?

Upvotes: 2

Views: 4213

Answers (3)

John K
John K

Reputation: 28927

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)

Upvotes: 8

lomaxx
lomaxx

Reputation: 115885

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

Upvotes: 4

James Black
James Black

Reputation: 41838

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

Upvotes: 1

Related Questions