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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top