C Sample Test,Sample questions

Question:
For the code snippet given below, which of the following statements are valid?

public class MyContainer<T> where T: class, IComparable
{
    //Insert code here
}
Class MyContainer requires that it's type argument must implement IComparable interface.
Compiler will report an error for this block of code.
There are multiple constraints on type argument to MyContainer class.
Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.

1.1 and 2 Only

2.. 3 and 4 Only

3.2 and 3 Only

4.All of the above


Question:
For the code snippet given below, which of the following statements are valid?

public class MyContainer<T> where T: IComparabte
{
    // Insert code here
}
1. Class MyContainer requires that it's type argument must implement IComparabte interface.
2. Type argument of class MyContainer must be IComparabte.
3. Compiler will report an error for this block of code.
4. This requirement on type argument is called as constraint.

1.1 and 2 Only

2.1,2 and 3 Only

3.1 and 4 Only

4.All of the above


Question:
For the code snippet given below, which of the following statements is valid?

public class Generic<T>
{
    public T Field;
}
class Program
{
    static void Main(string[ ] args)
    {
        Generic<String> g = new Generic<String>();
        g.Field = "Hello";
        Console.WriteLine(g.Field);
    }
}

1.It will print string "Hello" on the console.

2.Name Generic cannot be used as a class name because it's a keyword.

3.Compiler will give an error.

4.Member Field of class Generic is not accessible directly.


Question:
For the code snippet shown below, which of the following statements are valid?

public class Generic<T>
{
    public T Field; 
    public void TestSub()
    {
        T i = Field + 1;
    }
}
class MyProgram
{
    static void Main(string[] args)
    {
        Generic<int> gen = new Generic<int>();
        gen.TestSub();
    }
}

1.Addition will produce result 1.

2.Result of addition is system-dependent.

3.Program will generate run-time exception.

4.Compiler will report an error: Operator '+' is not defined for types T and int.


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

1.Program will compile and on execution will print: IndiaBIX 4.2

2.A non generic class Hello cannot have generic subroutine.

3.Compiler will generate an error.

4.Program will generate a run-time exception.


Question:
Which of the following statements are valid about generics in .NET Framework?

1. Generics is a language feature.
2. We can create a generic class, however, we cannot create a generic interface in C#.NET.
3. Generics delegates are not allowed in C#.NET.
4. Generics are useful in collection classes in .NET framework

1.1 and 2 Only

2. 1, 2 and 3 Only

3. 1 and 4 Only

4. All of the above


Question:
Which of the following statements is valid about advantages of generics? 

1.Generics shift the burden of type safety to the programmer rather than compiler.

2.Generics require use of explicit type casting.

3.Generics provide type safety without the overhead of multiple implementations.

4.Generics eliminate the possibility of run-time errors.


Question:
Which of the following statements is valid about generic procedures in C#.NET?

1.All procedures in a Generic class are generic.

2.Only those procedures labeled as Generic are generic.

3.Generic procedures can take at the most one generic parameter.

4.Generic procedures must take at least one type parameter.


Question:
Which one of the following classes are present System.Collections.Generic namespace?  1. Stack 2. Tree 3. SortedDictionary 4. SortedArray

1.1 and 2 only

2.2 and 4 only

3.1 and 3 only

4.All of the above


More MCQS

  1. C# MCQS -Programming (.NET Framework)
  2. C# MCQS -Programming(Control Instructions)
  3. C# MCQS - Functions and Subroutines(.NET Framework)
  4. C# Programming-Constructors
  5. C# Programming- Arrays
  6. C# Programming -Structures
  7. C# Programming-Properties
  8. C# Programming -Exception Handling
  9. C# Programming -Interfaces
  10. C# Programming -Delegates
  11. C# Programming -Generics
  12. C# Programming - Datatypes
  13. C# Programming- Operators
  14. C# Programming -Classes and Objects
  15. NET Programming mcqs
  16. Computer Science Engineering (CSE) .NET Programming
  17. C# Programming Mcq Set 1
  18. C# Programming Mcq Set 2
  19. C#.NET Programming Mcq
Learn ,Learn C Objetive choice questions and answers,C Multiple choice questions and answers,C objective, C questions , C answers,C MCQs questions and answer
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!