Qus:    How Can we pass 2 different type values to generic function?
Nov 27, 2020 13:45 2 Answers Views: 90 NAIDU

 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);

}

Prev Next
Answers (2)
PARTH Nov 28, 2020 02:40
Answer:   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);
}

RAMU Nov 28, 2020 09:55
Answer:   We can pass 2 different type values to generic collection. Please find the below code which demonstrates
Class MyClass
{
Internal static void print (Ta, Kb)
{
}
}
Class program
{
public static void Main ()
{
MyClass.print(05,"Besant");
Console.ReadLine ();
}
}

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect