const class references #2978
Replies: 4 comments
-
Sounds like this belongs on csharplang.
|
Beta Was this translation helpful? Give feedback.
-
const value needs to be known at compile time. static readonly value can be determined at runtime. |
Beta Was this translation helpful? Give feedback.
-
Probably more importantly than compile-time vs. runtime is how it's used ... I see |
Beta Was this translation helpful? Give feedback.
-
@mseld2 : the value is known at compile time, for certain values of “known”. In this case it is completely known as a timespan is basically a wrapper around an Int64. More generally , a way to embed non-primitive struts and classes in the resulting binary would be necessary, but it would also be useful for other things. @mv10-work : how it is used is pretty much the runtime vs compile time issue. And, yes if you change a const value you need to recompile all references to it for it to take effect. But that is in my experience both expected and desirable behavior. |
Beta Was this translation helpful? Give feedback.
-
This issue has been moved from a ticket on Developer Community.
I can do
static readonly TimeSpan MAXTIME = new TimeSpan(0, 0, 5);
so why can't I do
const TimeSpan MAXTIME = new TimeSpan(0, 0, 5);
??
These are identical to a developer....
Then I can use MAXTIME as a default in optional parameters.
Original Comments
Visual Studio Feedback System on 10/30/2019, 00:05 AM:
Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.
Beta Was this translation helpful? Give feedback.
All reactions