lapucca
asked on
What's the best way to declare and manage constants variables in a web application?
Hi, I'm using vs2012, C# and asp.net
What's the best way to organize and keep all constants used in my application? Should I create a class then in it, I would declare public properties with set and get? How would I set the value, string/int, in these properties using set? Also, declare a struct in side this class is okay? And, should I make this class static?
Thank you.
What's the best way to organize and keep all constants used in my application? Should I create a class then in it, I would declare public properties with set and get? How would I set the value, string/int, in these properties using set? Also, declare a struct in side this class is okay? And, should I make this class static?
Thank you.
What do you mean by a constant variable. There is a contradiction in there.
ASKER
Yes, you're correct about the contradiction. Thank you for catching that.
i want to have a way to ref some int and strings at one place. These will not be change inside the application but just used as reference for their values. For example, cell number for each cell in a grid based on their column name. strings with information that will be access in side the application.
It will make it easier to just keep it one place and changes are only done once there. I hope that makes sense about what I'm asking for.
i want to have a way to ref some int and strings at one place. These will not be change inside the application but just used as reference for their values. For example, cell number for each cell in a grid based on their column name. strings with information that will be access in side the application.
It will make it easier to just keep it one place and changes are only done once there. I hope that makes sense about what I'm asking for.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kaufmed, that is exactly what I'm trying to sort out. I'm not sure about using the nested class approach. My original thought is a static class but then problem how to group the related constant together. I thought about using struct in side the class but you can't assign values to a struct during declaring. But maybe just limit the class nesting to 2 levels might work?
ASKER
Kaufmed,
oops, got compile error when I use nested class. Cannot declare instance members in a static class. Please have a look, thank you.
const.txt
oops, got compile error when I use nested class. Cannot declare instance members in a static class. Please have a look, thank you.
const.txt
I'm not sure what you'd gain by using a struct. It's more or less the same concept as a class, except that structs are expected to be smaller in size (less than 16 B).
ASKER
Yes, there is an error in the error list for each of the declaration like this one:
Error 1 'XXXXXXXXXX.AppConstants.G ridColumnI ndex.Edit' : cannot declare instance members in a static class
That's strange that it looks fine in your.
Error 1 'XXXXXXXXXX.AppConstants.G
That's strange that it looks fine in your.
ASKER
that's strange. I added static key word in front of const then removed it. Now I compiled with no error. Thank you.
ASKER
I think VS was cached error or something weird happened. But it's cleared no, thank you.