You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn-pr/wwl-azure/design-resilient-code-interfaces/8-knowledge-check.yml
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,12 @@ title: Knowledge check
4
4
metadata:
5
5
title: Knowledge check
6
6
description: "Knowledge check"
7
-
ms.date: 02/14/2025
7
+
ms.date: 02/17/2025
8
8
author: wwlpublish
9
9
ms.author: eric
10
10
ms.topic: unit
11
+
ms.custom:
12
+
- N/A
11
13
durationInMinutes: 2
12
14
content: |
13
15
[!include[](includes/8-knowledge-check.md)]
@@ -21,7 +23,7 @@ quiz:
21
23
explanation: "Correct. Explicit interface members are only accessible through the interface instance, so you need to cast the class instance to the interface type."
22
24
- content: "By using the `this` keyword within the class."
23
25
isCorrect: false
24
-
explanation: "Incorrect. Explicit interface members cannot be accessed using the `this` keyword within the class; they are only accessible through the interface instance."
26
+
explanation: "Incorrect. Explicit interface members can't be accessed using the `this` keyword within the class; they're only accessible through the interface instance."
25
27
- content: "By using reflection to invoke the members."
26
28
isCorrect: false
27
29
explanation: "Incorrect. While reflection can be used to invoke members, it is not the standard way to access explicit interface members. The correct approach is to cast the class instance to the interface type."
Copy file name to clipboardExpand all lines: learn-pr/wwl-azure/design-resilient-code-interfaces/includes/3-implement-explicit-interface-members.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
In C#, explicit interface implementation allows a class to implement interface members in a way that they are only accessible through the interface, not the class instance. This is particularly useful when a class implements multiple interfaces with members that have the same signature.
1
+
In C#, explicit interface implementation allows a class to implement interface members in a way that they're only accessible through the interface, not the class instance. This is useful when a class implements multiple interfaces with members that have the same signature.
2
2
3
3
## Multiple interfaces in a class
4
4
5
-
A class in C# can implement multiple interfaces, allowing it to inherit behavior from various sources. This capability is crucial because C# does not support multiple inheritance of classes. By implementing multiple interfaces, a class can provide different functionalities and ensure that it adheres to the contracts defined by those interfaces.
5
+
A class in C# can implement multiple interfaces, allowing it to inherit behavior from various sources. The ability to combine multiple interfaces is crucial because C# doesn't support multiple inheritance of classes. Implementing multiple interfaces allows a class to have different features and ensures it follows the rules set by those interfaces.
6
6
7
7
- Interfaces define a group of related functionalities.
8
8
- A class or struct must implement all members of the interfaces it inherits.
@@ -28,7 +28,7 @@ public interface IMetricDimensions
28
28
29
29
In C#, a class can inherit from only one class but can implement multiple interfaces. This is especially important when several interfaces have the same member names. To avoid confusion, we use explicit interface implementation.
30
30
31
-
Explicit interface implementation ensures that each member of an interface has a unique implementation, preventing conflicts. It also clarifies which interface a member belongs to when a class implements two or more interfaces with the same member names. This allows a class to fulfill the requirements of multiple interfaces, providing diverse functionalities.
31
+
Explicit interface implementation ensures that each member of an interface has a unique implementation, preventing conflicts. It also clarifies which interface a member belongs to when a class implements two or more interfaces with the same member names. Explicit interface implementation allows a class to fulfill the requirements of multiple interfaces, providing diverse functionalities.
32
32
33
33
To explicitly implement a member of an interface, you add the interface name and a period before the member name. Here's an example:
34
34
@@ -64,7 +64,7 @@ In this code, the `Box` class is implementing two interfaces: `IEnglishDimension
64
64
65
65
## Use explicit interface members
66
66
67
-
To execute and test code that utilizes explicit interface members, you need to create instances of the interfaces and call their members. This ensures that the correct implementation is invoked based on the interface type.
67
+
You need to create instances of the interfaces and call their members to execute and test code that utilizes explicit interface members. This ensures that the correct implementation is invoked based on the interface type.
68
68
69
69
```csharp
70
70
Boxbox=newBox();
@@ -77,7 +77,7 @@ Console.WriteLine($"Length in centimeters: {mDimensions.Length()}");
77
77
Console.WriteLine($"Width in centimeters: {mDimensions.Width()}");
78
78
```
79
79
80
-
In this example, the `Box` class instance is cast to both `IEnglishDimensions` and `IMetricDimensions` to access the explicit interface members. The output will display the dimensions in both English and metric units.
80
+
In this example, the `Box` class instance is cast to both `IEnglishDimensions` and `IMetricDimensions` to access the explicit interface members. The output displays the dimensions in both English and metric units.
0 commit comments