Hi
How to add a ReadOnly property in C#.NET?
Add a ReadOnly property in C#.NET
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit PatelRank #622 · 3.8K reputationPosted Sep 12, 2012, 2:54 AM EDT
public int MyProperty { get; private set; }
And
public int MyProperty { get; }
VulpesRank #55 · 29.2K reputationPosted Sep 12, 2012, 4:21 AM EDT
int _myInt
public int MyProperty { get { return _myInt; } }
This is because 'auto-implemented' properties must have both a getter and setter even though the access modifier can differ for the two.