C# (Sharp) Programming Language Question: Download C# (Sharp) Programming Language PDF

Is it possible to have different access modifiers on the get/set methods of a property in C#?

Tweet Share WhatsApp

Answer:

No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.

Download C# (Sharp) Programming Language PDF Read All 163 C# (Sharp) Programming Language Questions
Previous QuestionNext Question
Is it possible to inline assembly or IL in C# code? Is it possible to have a static indexer in C#?