Interview Question
Qus: How Can we pass 2 different type values to generic function?
You can refer to below example to understand on how to pass 2 different type values to generic function
public class GenericMethod {
public static void sampleMethod(T[] array, string element ) {
Console.WriteLine(Arrays.toString(array));
Console.WriteLine(element);
}
public static void main(String args[]) {
Integer [] intArray = {24, 56, 89, 75, 36};
String str = "hello";
sampleMethod(intArray, str);
}
Answers (2)
public class GenericMethod {
public static void sampleMethod(T[] array, string element ) {
Console.WriteLine(Arrays.toString(array));
Console.WriteLine(element);
}
public static void main(String args[]) {
Integer [] intArray = {24, 56, 89, 75, 36};
String str = "hello";
sampleMethod(intArray, str);
}
Class MyClass
{
Internal static void print (Ta, Kb)
{
}
}
Class program
{
public static void Main ()
{
MyClass.print(05,"Besant");
Console.ReadLine ();
}
}