tag:blogger.com,1999:blog-5359546512544809971.post8445418178039388965..comments2024-03-29T00:46:49.972-07:00Comments on Jeremy Bytes: C# 8 Interfaces: Properties and Default ImplementationJeremyhttp://www.blogger.com/profile/06749690234470413216noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5359546512544809971.post-29021101751471212172022-05-19T10:31:26.331-07:002022-05-19T10:31:26.331-07:00Hi Jeremy,
a default implementation for a propert...Hi Jeremy,<br /><br />a default implementation for a property setter makes sense if it refers to other properties that are already in the interface.<br /><br />In your example. you could have this default property:<br />`double SideLengthInInch<br /> {<br /> get => SideLength / 2.54;<br /> set => SideLength = value * 2.54;<br /> }<br />`<br />Kristofhttps://www.blogger.com/profile/01727380410232817527noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-16234417690415710442021-07-23T20:48:33.510-07:002021-07-23T20:48:33.510-07:00I'm finding that if I create an abstract base ...I'm finding that if I create an abstract base class with a default readonly property the default implementation is not inherited from the base class abstraction. Is there a work around for this? Zachhttps://www.blogger.com/profile/05780791363522906896noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-81248510248943894002021-02-05T07:50:57.455-08:002021-02-05T07:50:57.455-08:00I use a static property of dictionary as a workaro...I use a static property of dictionary as a workaround to mimic the behaviour of a backing field.<br />The dictionary has any instance of the interface as the key, and the value of a particular property as the value. So one static property of dictionary provides backing fields for all instances of this interface.<br />I do not know if this breaks the philosophy of interface. But there are some cases where I really want to use interface rather than class inheritance. Anonymoushttps://www.blogger.com/profile/12908980888900647687noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-42296766220084278332019-12-03T21:30:15.389-08:002019-12-03T21:30:15.389-08:00Thank you for the post!Thank you for the post!Hellarenhttps://www.blogger.com/profile/17379540610886590005noreply@blogger.com