question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create readonly and constant variable easily

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

8reactions
jborean93commented, Mar 16, 2021

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.

3reactions
vexx32commented, Mar 17, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found