hello,
i am pretty sure this has been asked. although i have not found a discussion about this on stackoverflow. please redirect me if there is a duplicate to this one.
i need to implement a read only property on my type. moreover the value of this property is going to be set in the constructor and it is not going to be changed (i am writing a class that exposes custom routed UI commands for WPF but it does not matter).
i see two ways to do it:
1.
class MyClass { public readonly object MyProperty = new object(); }
2.
class MyClass { private readonly object my_property = new object(); public object MyProperty { get { return my_property; } } }
with all these FxCop errors saying that i should not have public member variables, it seems that the second one is the right way to do it. correct?
is there any difference between a get only property and a read only member in this case?
i wold appreciate any comments/advice/etc.
konstantin