C# Programming - Generics - Discussion

Discussion Forum : Generics - General Questions (Q.No. 5)
5.
For the code snippet shown below, which of the following statements are valid?
public class TestIndiaBix
{
    public void TestSub<M> (M arg)
    {
        Console.Write(arg);
    }
}
class MyProgram
{
    static void Main(string[] args)
    {
        TestIndiaBix bix = new TestIndiaBix();
        bix.TestSub("IndiaBIX ");
        bix.TestSub(4.2f);
    }
}
Program will compile and on execution will print: IndiaBIX 4.2
A non generic class Hello cannot have generic subroutine.
Compiler will generate an error.
Program will generate a run-time exception.
None of the above.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
1 comments Page 1 of 1.

Srikanth said:   1 decade ago
It will take a default type as generic type. So if we pass int value in the generic method it will act as a int generic method.

Post your comments here:

Your comments will be displayed after verification.