-
Aug 9th, 2018, 09:19 AM
#1
Thread Starter
Lively Member
Global Constants and Variables
There seems to be a lot of arguments over the use of Global variables in C# - I'm an 'old' programmer, so what I consider 'best practice' - or was 30yrs ago - has changed somewhat... hehe
I've read a bunch of posts on various forums, but most responses are a bit flippant - not offering a solution, just saying not to use globals - so I'll try to ask here
The application is a scientific one...I am looking for the 'best practice'
2 things (related) -
one - I have a bunch of constants - 200 or so - they are ACTUAL constants, not just programmatic ones - ergo unless the nature of the universe changes, they won't - I'm thinking one of these ideas, just not sure which
Code:
class Constants
{
// Idea #1
public decimal hDensity { get;} = 1.1209381092831M;
//Idea #2
public static decimal hDensity { get;} = 1.1209381092831M;
//Idea #3
public const decimal hDensity { get;} = 1.1209381092831M;
//Idea #4
public static decimal hDensity => 1.1209381092831M;
}
//OR should I use a struct - Idea #5
struct TheConstants
{
// definitions
}
SECOND - I have a bunch of user settings - not often changed, but.... (both UI related and mathematical stuff)
I was thinking of using a class or struct also - obviously with get/set this time - likely static.... (??) - and reading those values in from an XML file on launch - and writing to that XML file when needed (I may also include some min/max data in the XML file to limit appropriately the allowable values...
I know I can make this work.... but is it the 'best' and/or proper way??? and which ideas are 'proper'
There was a suggestion to use a db (e.g. access) - I really don't like that idea - too much overhead I think for something needed 99.9% of the time ONLY at app launch....
I appreciate this - I assume there have been similar questions, but the ones I've read so far don't seem to be answered seriously (if I can say that)
Cheers.... Scott
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|