How to make a reference type property “readonly”

后端 未结 8 707
青春惊慌失措
青春惊慌失措 2020-12-28 20:23

I have a class Bar with a private field containing the reference type Foo. I would like to expose Foo in a public property, but I do n

8条回答
  •  甜味超标
    2020-12-28 20:36

    Unfortunately, there's no easy way around this in C# at the moment. You could extract the "read only part" of Foo in an interface and let your property return that instead of Foo.

提交回复
热议问题