C# Programming - Generics - Discussion

Discussion :: 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);
    }
}

[A]. Program will compile and on execution will print: IndiaBIX 4.2
[B]. A non generic class Hello cannot have generic subroutine.
[C]. Compiler will generate an error.
[D]. Program will generate a run-time exception.
[E]. None of the above.

Answer: Option A

Explanation:

No answer description available for this question.

Srikanth said: (Oct 28, 2011)  
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:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.