Global Constants for C#… sorta

Since C# now supports using static System.String; to get to the string static classes, we can now use this to create global constants.

So now you can do something like:

namespace MyCommonNamespace
public static class GlobalConstants
public const string MyConstant = "Some String Value";

To use, just add the following to your using collection:

using static MyCommonNamespace.GlobalConstants;

Now you can use the following inside of your code:

var LocalVariable = MyConstant;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.