Can I create an automatic property (no private member) with get and set code?

前端 未结 4 585
后悔当初
后悔当初 2021-01-24 02:14

In c#, I can do this:

public int Foo { get; set; }

Which is nice. But as soon as I want to do anything in the getter or setter, I have to chang

4条回答
  •  难免孤独
    2021-01-24 02:48

    With automatic properties, the compiler generates a backing field for you. A custom getter/setter requires that you manually create a backing field to work with. The ability to specify a custom getter/setter on an automatic property would essentially make it act just like a method, since there's nothing to get or set.

提交回复
热议问题