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

Multiple generic parameters 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 class with two type parameters.

C Sharp (C#)
public class Pair<[1], U> { }
Drag options to blanks, or click blank then click option'
AT
Bint
Cstring
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using concrete types like int or string instead of type parameters.
Using keywords like var as type parameters.
2fill in blank
medium

Complete 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'
AT
Bstring
Cint
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using concrete types instead of generic parameters.
Using invalid identifiers as generic parameters.
3fill in blank
hard

Fix 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'
A1T
BT1
CT
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Starting generic parameter names with numbers.
Using reserved keywords or concrete types.
4fill in blank
hard

Fill 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'
AT
Bint
Cvoid
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type when a value is returned.
Using concrete types as generic parameters.
5fill in blank
hard

Fill 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'
AT
BU
DV
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up generic parameter names in constraints.
Using invalid identifiers for generic parameters.