C# automatic properties - is it possible to have custom getter with default setter?

后端 未结 5 1108
清酒与你
清酒与你 2021-01-04 13:44

It\'s possible I shouldn\'t even be attempting this in the first place, but here\'s what I have so far:

public List AuthorIDs
{
    get
    {
             


        
5条回答
  •  心在旅途
    2021-01-04 14:47

    No, it's not possible. Either everything is explicit, or the whole property is automatic. Anyway, in that case the setter doesn't seem to make any sense... there should be no setter at all.

    Also, I think you should make it a method. It would make it clearer to the caller that it performs a possibly lenghty calculation. It's also against guidelines to perform complex processing in a property.

提交回复
热议问题