Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a generic class with two type parameters.
C Sharp (C#)
public class Pair<[1], U> { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using concrete types like int or string instead of type parameters.
Using keywords like var as type parameters.
✗ Incorrect
The first generic type parameter is usually named T by convention.
2fill in blank
mediumComplete the method signature to use two generic parameters.
C Sharp (C#)
public void Swap<[1], V>(ref T a, ref V b) { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using concrete types instead of generic parameters.
Using invalid identifiers as generic parameters.
✗ Incorrect
The method uses two generic parameters: T and V.
3fill in blank
hardFix the error in the generic class declaration.
C Sharp (C#)
public class Container<[1], U> { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting generic parameter names with numbers.
Using reserved keywords or concrete types.
✗ Incorrect
Generic type parameters must be valid identifiers, usually a single uppercase letter like T.
4fill in blank
hardFill both blanks to declare a generic method with two parameters and return type.
C Sharp (C#)
public [1] Combine<[2], V>(T first, V second) { return default; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type when a value is returned.
Using concrete types as generic parameters.
✗ Incorrect
The method returns a string and has generic parameters T and V.
5fill in blank
hardFill all three blanks to declare a generic class with constraints on two parameters.
C Sharp (C#)
public class Repository<[1], [2]> where [3] : class where U : new() { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up generic parameter names in constraints.
Using invalid identifiers for generic parameters.
✗ Incorrect
The class has generic parameters T and U. The constraint where T : class applies to T.