Pair with two generic type parameters: T1 and T2.First of type T1 and Second of type T2.First and Second.Pair with string and int types.First and Second.Pair with two generic type parameters: T1 and T2.First of type T1 and Second of type T2.First and Second.Pair with string and int types.First and Second.Pair with two generic type parameters T1 and T2. Inside the class, declare two public fields: First of type T1 and Second of type T2.Use public class Pair<T1, T2> to declare the class with two generic parameters.
Pair class that takes two parameters: first of type T1 and second of type T2. Inside the constructor, set the fields First and Second to these parameters.Constructor name must match the class name Pair. Assign parameters to fields inside the constructor.
Main method, create an instance of Pair with string as T1 and int as T2. Name the variable myPair and initialize it with the values "apple" and 5.Use new Pair<string, int>("apple", 5) to create the instance.
Console.WriteLine statements in the Main method to print the values of myPair.First and myPair.Second.Use Console.WriteLine(myPair.First); and Console.WriteLine(myPair.Second); to print the values.
What is the correct way to declare a generic class with two type parameters in C#?
class MyClass<T1, T2> { }Which of the following is the correct syntax to declare a method with two generic parameters in C#?
public void Swap<T1, T2>(T1 a, T2 b) { }What will be the output of the following C# code?
class Pair<T1, T2> {
public T1 First;
public T2 Second;
public Pair(T1 first, T2 second) {
First = first;
Second = second;
}
public override string ToString() {
return $"{First} and {Second}";
}
}
var p = new Pair<int, string>(5, "hello");
Console.WriteLine(p);Identify the error in the following code snippet:
class Container<T1, T2> {
public T1 Item1;
public T2 Item2;
public Container(T1 item1, T2 item2) {
Item1 = item1;
Item2 = item2;
}
}
var c = new Container<int>(5, 10);Given the following generic method, what is the correct way to call it with two different types?
public static void PrintPair<T1, T2>(T1 first, T2 second) {
Console.WriteLine($"First: {first}, Second: {second}");
}Choose the correct call:
Pass the test and this pattern moves unknown