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

Generic interfaces 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 generic interface named IRepository.

C Sharp (C#)
public interface [1]<T> { void Add(T item); }
Drag options to blanks, or click blank then click option'
AIRepository
BICollection
CIList
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of interface name.
Omitting the generic type parameter .
Not starting interface name with 'I'.
2fill in blank
medium

Complete the code to implement the generic interface IRepository for a class named Repository.

C Sharp (C#)
public class Repository<T> : [1]<T> { public void Add(T item) { /* implementation */ } }
Drag options to blanks, or click blank then click option'
AIEnumerable
BIRepository
CICollection
DIList
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-generic interface.
Forgetting to specify the generic type parameter .
Using a different interface name.
3fill in blank
hard

Fix the error in the interface method declaration to make it generic.

C Sharp (C#)
public interface IRepository<T> { void [1](T item); }
Drag options to blanks, or click blank then click option'
AAppend
BInsert
CAddItem
DAdd
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that are not standard or expected.
Using names that do not clearly indicate adding an item.
4fill in blank
hard

Fill both blanks to declare a generic interface with a method that returns an item by index.

C Sharp (C#)
public interface [1]<T> { T [2](int index); }
Drag options to blanks, or click blank then click option'
AIRepository
BGetItem
CGet
DIList
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of interface name.
Using a method name that is too long or unclear.
5fill in blank
hard

Fill all three blanks to implement a generic interface with Add and Get methods in a class.

C Sharp (C#)
public class [1]<T> : [2]<T> { private List<T> items = new List<T>(); public void Add(T item) { items.Add(item); } public T [3](int index) { return items[index]; } }
Drag options to blanks, or click blank then click option'
ARepository
BIRepository
CGet
DIList
Attempts:
3 left
💡 Hint
Common Mistakes
Using interface name as class name.
Forgetting to implement the interface.
Using incorrect method names.