Question

This is basically a a design question:

I am rewriting an application in C# which is basically written in C++. C++ has this nice concept of Header files which will gold a lot of declared constant values for the consuming file.

However, we do not have Header files in C#. I may have two options

  1. Create a class which will hold a lot of constant values for me(No so standard)
  2. Store values in XML (Standard-But involves a lot of parsing hassle)

Which is a better solution? Is there any other solution that I may not know of?

Was it helpful?

Solution

Personally i'd use a static class and place all the values in there.

public static class Constants
{
   public const int Ten = 10;
   public const int Twenty = 20;
   ....
}

EDIT

As @JonSkeet suggested, it's better if you store these values in classes they pertain to, however, that might not always be possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top