G
G
GetB2014-09-09 17:18:35
.NET
GetB, 2014-09-09 17:18:35

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";
}

I have dozens and dozens of such classes, sometimes hundreds of constants.
Attention, question!
It is a good idea to store a large number of constants, and if not, how can all this be implemented differently?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Guketlev, 2014-09-09
@GetB

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";
        }
}

A
aush, 2014-09-10
@aush

For such things, there is a standard built-in tool - resource (.resx) files.

S
Sergey, 2014-09-09
Protko @Fesor

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?

A
Alexey, 2014-09-09
@HaJIuBauKa

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 question

Ask a Question

731 491 924 answers to any question