If I have a property in my class, how do I allow it to be publicly accessible without it being writable? I know this is simple, but I haven't worked with C# in a while and I'm blanking on stuff.
| SitePoint Sponsor |



If I have a property in my class, how do I allow it to be publicly accessible without it being writable? I know this is simple, but I haven't worked with C# in a while and I'm blanking on stuff.

works for me!Code:private int x; public int X { get { return x; } }
Web Application Development & Maintenance



Ok, I thought there was a variable type that already did that, but maybe I'm thinking of Ruby.



There is also readonly.





Yep. And there is implicit property (C# 3.0):
Code:public int X { get; private set; }

Bookmarks