0
0
C Sharp (C#)programming~10 mins

Multiple interface implementation in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AIFirst, ISecond
BIFirst ISecond
CIFirst & ISecond
DIFirst | ISecond
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.
2fill in blank
medium

Complete 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'
AMethodA
BMyClass
CISecond
DIFirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the interface name.
Omitting the interface name prefix.
3fill in blank
hard

Fix 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'
A,
B;
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolon or other symbols instead of comma.
Leaving out the separator entirely.
4fill in blank
hard

Fill 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'
AIFirst
BMyClass
CISecond
DMethodA
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of interface names.
Mixing up interface names between methods.
5fill in blank
hard

Fill 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'
Akvp
Bkvp.Key
Ckvp.Value
Dm
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable names in lambdas.
Mixing keys and values in the wrong places.