RE: Is it possible to have different access modifiers on the get/set methods of a property? Justify
Yes It is possible to have different access modifiers but the best approach is to use all access modifiers as public for efficient data retrieval. public String EMPNO
RE: Is it possible to have different access modifiers on the get/set methods of a property? Justify
Yes It is possible to assign different access modifiers but the efficient approach is make all modifiers to public for accessibility public String EMPNO
RE: Is it possible to have different access modifiers on the get/set methods of a property? Justify
You can have different access modifiers applied to the get and set methods.
public class Myclass { private string _MyProperty; public string MyProperty { get { return _MyProperty; } internal set { _MyProperty value; } } }
Thus types in the same assembly as MyClass have access to the set method.However the get method is public.This situation is very common in day to day applications where only a specified set of classes can set the value while most of the classes can read the values.
In short the restricion is always to a more restrictive level and only one accessor can be modified - for instance: public int MyInt { get { return m_MyInt; } private set { m_MyInt value; } }
will compile but:
private int MyInt { get { return m_MyInt; } public set { m_MyInt value; } } will not compile nor will:
public int MyInt { protected get { return m_MyInt; } private set { m_MyInt value; } }