Is it ok to omit get or set in an automatic property when it is declared virtual?
I am referring a book on C# which shows the members of System.Exception as follows :
// Properties
public virtual IDictionary Data { get; }
public virtual string HelpLink { get; set; }
public Exception InnerException { get; }
public virtual string Message { get; }
public virtual string Source { get; set; }
public virtual string StackTrace { get; }
public MethodBase TargetSite { get; }
If automatic properties need to have both get and set, then why is it ok here?
Thanks.
This looks like an abbreviated signature for the properties, rather than their actual implementation.
I’ve not gone to reflector, but you could imagine the above signature for
Exception.Databeing implemented in one of two manners:Or:
All the implementor needs to know is that they may only have a public getter in their override.