Answer the question
In order to leave comments, you need to log in
What is the best way to store a large number of constant values in C#?
I am writing a PCL library for developers. You need to store a very large number of constant values.
Some methods have a List as a parameter. It should store string parameters that will be used when generating a request to the server. The user will not need to manually enter parameters in the List, but simply select the desired constants from the desired classes.
I have set the parameters like this:
class A
{
public const string DamageAvg = "damage_avg";
public const string DamageAvgRank = "damage_avg.rank";
public const string DamageAvgRankDelta = "damage_avg.rank_delta";
public const string DamageAvgValue = "damage_avg.value";
}
Answer the question
In order to leave comments, you need to log in
You can use nested classes
static class A
{
public static class DanageAvg {
public const string Self = "damage_avg";
public const string Rank = "damage_avg.rank";
public const string RankDelta = "damage_avg.rank_delta";
public const string Value = "damage_avg.value";
}
public static class Other {
public const string Self = "other_value";
public const string Somthing = "other_value.something";
public const string Other = "other_value.other";
}
}
For such things, there is a standard built-in tool - resource (.resx) files.
Since Enum only supports int, you will have to come up with various tricks .
what do you need these constants for, where are they used? Perhaps you can get rid of them?
Enum has a Description attribute that can be read. You can implement / hang other attributes.
Only here what for to store such amount of the necessary data in constants.
The user will choose them where? If in the UI interface it is probably worth switching to a database or XML storage? Then everything will be strictly cataloged and structured. And so some kind of "porridge" turns out in the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question