create readonly and constant variable easily
See original GitHub issueHi Guys !!
we can create readonly and constant variable with new-variable and set-variable cmdlets but its much easily and natural to use this syntax :
[ReadOnly]$var1 = 1
[Constant]$var2 = 2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:22 (13 by maintainers)
Top Results From Across the Web
Difference between readonly and const keyword in C# - ...
In C#, constant fields are created using const keyword. ReadOnly is a runtime constant. Const is a compile time constant. The value of...
Read more >How to create readonly constant variables
Use the readonlyConst() function to prevent programmers from updating static constant variables. Implementation [top]. It is a recommended Best Practice Name “ ...
Read more >Const and Read-Only in C# with Examples
In this article, I am going to discuss the keywords Const and Read-only in C# with examples. Both are used to create constant...
Read more >c# - const vs. readonly
A readonly variable is still a variable, it can't be a constant. Variable and constant are mutually exclusive.
Read more >Readonly and Constant Variables in C#
Readonly constant's value can be set through the reference variable. Readonly constant variables are runtime time constant variables.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We can definitely have attributes on a var like
[ValidateNotNull()]$var
so extending that further like[ReadOnly()]
or[Constant()]
doesn’t seem too hard of an ask. The different between an attribute and type here are the parenthesis.I don’t agree. We currently have scope modifiers.
$private:
is the only real outlier, but that’s mainly an implementation detail. All the current scope modifiers are just that.“readonly” is not a scope. Nor is “constant”. Neither of those properties are scopes. They’re properties of a variable.
And yeah, it won’t come naturally. Good. There are irritating caveats and weirdness associated with using readonly or constant variables. Folks who use them should be well aware before they stumble into a day’s worth of needless confusion resulting from careless use.