I’m trying to understand the design considerations of the team that created the method Environment.GetCommandLineArgs.
It could have been a static property, very much like System.Web.HttpContext.Current. After all, the returned value should not change once available. So it’s more like a property of the current running process.
I know that any property in .NET is a syntactic sugar to getter/setter methods. But that’s the exact reason for using a property rather than an explicit getter method.
Or maybe there is there something I’m missing here?
What do you think?
I suspect it’s because it makes a copy of the array each time you call it. For example, consider this program:
If you run this with “test original” it will still print out “original”.
So when you say:
Actually, it will return a different value (a new array reference) on every call, precisely because arrays are always mutable.