Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class that implements two interfaces.
C Sharp (C#)
interface IFirst { void MethodA(); }
interface ISecond { void MethodB(); }
class MyClass : [1] {
public void MethodA() { }
public void MethodB() { }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or symbols instead of commas between interface names.
Trying to use '&' or '|' which are not valid here.
✗ Incorrect
In C#, multiple interfaces are implemented by listing them separated by commas.
2fill in blank
mediumComplete the code to explicitly implement the MethodA from IFirst interface.
C Sharp (C#)
interface IFirst { void MethodA(); }
class MyClass : IFirst {
void [1].MethodA() {
Console.WriteLine("First");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the interface name.
Omitting the interface name prefix.
✗ Incorrect
Explicit interface implementation requires prefixing the method with the interface name.
3fill in blank
hardFix the error in the code by completing the interface implementation syntax.
C Sharp (C#)
interface IFirst { void MethodA(); }
interface ISecond { void MethodB(); }
class MyClass : IFirst [1] ISecond {
public void MethodA() { }
public void MethodB() { }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolon or other symbols instead of comma.
Leaving out the separator entirely.
✗ Incorrect
Interfaces must be separated by commas in the class declaration.
4fill in blank
hardFill both blanks to complete the explicit implementation of two interfaces in the class.
C Sharp (C#)
interface IFirst { void MethodA(); }
interface ISecond { void MethodB(); }
class MyClass : IFirst, ISecond {
void [1].MethodA() {
Console.WriteLine("First");
}
void [2].MethodB() {
Console.WriteLine("Second");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of interface names.
Mixing up interface names between methods.
✗ Incorrect
Explicit implementation requires prefixing each method with its interface name.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps interface names to method names if method name length is greater than 5.
C Sharp (C#)
var methods = new Dictionary<string, string[]> {
{ "IFirst", new string[] { "MethodA", "Init" } },
{ "ISecond", new string[] { "MethodB", "Start" } }
};
var filtered = methods.ToDictionary(
[1] => [2],
[3] => [3].Value.Where(m => m.Length > 5).ToArray()
); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable names in lambdas.
Mixing keys and values in the wrong places.
✗ Incorrect
In ToDictionary, the first lambda gets the key (kvp.Key), the second gets the value (kvp.Value).