From 4d4637a917a8af3439091862abcb6f25257fb97a Mon Sep 17 00:00:00 2001 From: Mark J Price Date: Thu, 12 Oct 2023 07:23:13 +0100 Subject: [PATCH] Update improvements.md --- docs/errata/improvements.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/errata/improvements.md b/docs/errata/improvements.md index 157ad8f..450f9d6 100644 --- a/docs/errata/improvements.md +++ b/docs/errata/improvements.md @@ -672,7 +672,8 @@ public class Human : IGamePlayer, IKeyHolder WriteLine("Implementation for losing a key."); } - void IGamePlayer.Lose() // Explicit implementation can be private. + // Explicit implementation can be any access modifier. + void IGamePlayer.Lose() // Defaults to private. { WriteLine("Implementation for losing a game."); } @@ -685,16 +686,21 @@ I will also update the code to show how to use the class, as shown in the follow #region Calling implicit and explicit implementations Human human = new(); -human.Lose(); // Calls the implicit implementation i.e. losing a key. +human.Lose(); // Calls the public implicit implementation. +// Outputs: Implementation for losing a key. ((IGamePlayer)human).Lose(); // Calls the explicit implementation. +// Outputs: Implementation for losing a game. IGamePlayer player = human as IGamePlayer; -player.Lose(); // Calls explicit implementation of losing a game. +player.Lose(); // Calls the explicit implementation. +// Outputs: Implementation for losing a game. #endregion ``` +> Note that although the implementation of `IGamePlayer.Lose` in `Human` is `private`, the `IGamePlayer.Lose` member itself has an access modifier of `public`, so if we cast the `Human` instance into the interface type then that `Lose` implementation is accessible. + # Page 270 - Equality of types > Thanks to [Masoud Nazari](https://github.com/MAS-OUD) for raising this [issue on 17 March 2023](https://github.com/markjprice/cs11dotnet7/issues/44).