troubleshooting Question

What are the differences when assigning global variables in C#?

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
10 Comments1 Solution36 ViewsLast Modified:
What is the difference between defining a value for a parameter? I assume setting it as const assigns it a value and its value cannot be changed. Assigning it as static assigns it a value that can be changed. But what does the third method allow that the others do not. Why define it this way? I am still learning C# and trying to adopt best practices. In this case I have a section of code that will instantiate these as global variables to be used throughout the entire application.

public const DateTime ApplyDate = Convert.ToDateTime("1900-01-01 00:00:00.000");

public static DateTime ApplyDate = Convert.ToDateTime("1900-01-01 00:00:00.000");

static public DateTime ApplyDate
    get { return Convert.ToDateTime("1900-01-01 00:00:00.000"); }
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros