How can make a variable (not class member) "read only" in C#
Posted
by
devfreak
on Stack Overflow
See other posts from Stack Overflow
or by devfreak
Published on 2011-01-08T17:42:38Z
Indexed on
2011/01/08
17:54 UTC
Read the original article
Hit count: 128
Hi, I'm new to the C# world and I can't find a method to declare read only variable in C# (something like declaring "const" variable in c++). Is there one?
I'll give you an example:
...
int f() { return x; } // x is not const member
...
void g() {
int readOnlyVar = f(); // is there a method to declare readOnlyVar as read only or const
// Some code in which I want to restrict access to readOnlyVar to read only
}
© Stack Overflow or respective owner