Explore topic-wise MCQs in C Sharp Programming.

This section includes 28 Mcqs, each offering curated multiple-choice questions to sharpen your C Sharp Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

Choose the statements which are valid for given code snippet:

A. code runs successfully but prints nothing
B. code runs successfully and prints 1
C. program will give run time error
D. compile time error
Answer» E.
2.

Which statement is valid for the given snippet of code:

A. Compile time error
B. Generic being a keyword cannot be used as a class name
C. Run time error
D. Code runs successfully
Answer» E.
3.

For the code set given below,which of the following statements are perfectly valid?

A. Class MyConatiner requires that its type argument must implement Icomparable interface
B. There are multiple constraints on type argument to MyConatiner class
C. Compiler will report an error
D. None of the mentioned
Answer» C. Compiler will report an error
4.

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

A. Addition will produce result 1.
B. Result of addition is system-dependent.
C. Program will generate run-time exception.
D. Compiler will report an error: Operator '+' is not defined for types T and int.
Answer» E.
5.

For the code given below which statements are perfectly valid?

A. Run time exception error
B. Compile time error
C. Code runs successfully and prints required output
D. None of the mentioned
Answer» D. None of the mentioned
6.

Which of these is a correct way of defining generic method?

A. name(T1, T2, …, Tn) { /* … */ }
B. public name { /* … */ }
C. class name[T1, T2, …, Tn] { /* … */ }
D. name{T1, T2, …, Tn} { /* … */ }
Answer» C. class name[T1, T2, …, Tn] { /* … */ }
7.

With which of the following can the ref keyword be used?1. Static data2. Instance data3. Static function/subroutine4. Instance function/subroutine

A. 1, 2
B. 3, 4
C. 1, 3
D. 2, 4
Answer» C. 1, 3
8.

Which one of the following classes are present System.Collections.Generic namespace?1. Stack2. Tree3. SortedDictionary4. SortedArray

A. 1 and 2 only
B. 2 and 4 only
C. 1 and 3 only
D. All of the above
Answer» D. All of the above
9.

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

A. Program will compile and on execution will print: CompSciBits 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.
Answer» B. A non generic class Hello cannot have generic subroutine.
10.

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

A. It will print string "Hello" on the console.
B. Name Generic cannot be used as a class name because it's a keyword.
C. Compiler will give an error.
D. Member Field of class Generic is not accessible directly.
Answer» B. Name Generic cannot be used as a class name because it's a keyword.
11.

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.5. None of the above

A. 1 and 2 Only
B. 1, 2 and 3 Only
C. 1 and 4 Only
D. All of the above
Answer» D. All of the above
12.

For the code snippet given below, which of the following statements are valid?public class MyContainer 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.

A. 1 and 2 Only
B. 1, 2 and 3 Only
C. 1 and 4 Only
D. All of the above
Answer» D. All of the above
13.

For the code snippet given below, which of the following statements are valid?public class MyContainer where T: class, IComparable{ //Insert code here}1. Class MyContainer requires that it's type argument must implement IComparable interface.2. Compiler will report an error for this block of code.3. There are multiple constraints on type argument to MyContainer class.4. Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.

A. 1 and 2 Only
B. 3 and 4 Only
C. 2 and 3 Only
D. All of the above
Answer» C. 2 and 3 Only
14.

Which of the following is the correct way to call the function abc() of the given class csharp given below?

A. delegate void del(int a);csharp s = new csharp();del d = new del(ref s.abc);d(10);
B. csharp s = new csharp();delegate void d = new del(ref abc);d(10);
C. delegate int del(int a);del d;csharp s = new csharp();d = new del(ref s.fun);d(10);
D. none of the mentioned
Answer» D. none of the mentioned
15.

Which of the following is the correct way to call the subroutine function abc() of the given class csharp given below?

A. csharp c = new csharp();delegate void d = new del(ref abc);d();
B. delegate void del();del d;csharp s = new csharp();d = new del(ref s.abc);d();
C. csharp s = new csharp();delegate void del = new delegate(ref abc);del();
D. None of the mentioned
Answer» C. csharp s = new csharp();delegate void del = new delegate(ref abc);del();
16.

What will be the output of the given code snippet below?

A. Test Your
B. Test-Your-C#.NET-Skills
C. ur C#.NET Skills
D. None of the mentioned
Answer» C. ur C#.NET Skills
17.

Choose the correct way to call subroutine fun() of the sample class?

A. delegate void del(int i);x s = new x();del d = new del(ref s.x);d(8, 2.2f);
B. delegate void del(int p, double k);del d;x s = new x();d = new del(ref s.x);d(8, 2.2f);
C. x s = new x();delegate void d = new del(ref x);d(8, 2.2f);
D. all of the mentioned
Answer» C. x s = new x();delegate void d = new del(ref x);d(8, 2.2f);
18.

Which among the given classes represents System.Collections.Generic namespace?

A. SortedDictionary
B. Sorted Array
C. Stack
D. All of the mentioned
Answer» B. Sorted Array
19.

Incorrect statements about delegates are?

A. Delegates are reference types
B. Delegates are object oriented
C. Delegates are type safe
D. Only one method can be called using a delegate
Answer» E.
20.

What will be the output of given set of code?

A. Test Ykur C#.NET Skills
B. Test Ykour C#.NET Skills
C. Test Your C#.NET Skills
D. Test ur C#.NET Skills
Answer» D. Test ur C#.NET Skills
21.

What does the following code set defines?public Gen(T o) { ob = o; }

A. Generics class decleration
B. Declaration of variable
C. Generic constructor declaration
D. All of the mentioned
Answer» D. All of the mentioned
22.

Which of the following is a valid statement about generic procedures in C#.NET are?

A. All procedures in a Generic class are generic
B. Generic procedures should take at least one type parameter
C. Only those procedures labeled as Generic are Generic
D. None of the mentioned
Answer» C. Only those procedures labeled as Generic are Generic
23.

Which among the following is the correct statement about delegate declaration ?delegate void del(int i);

A. on declaring the delegate, a class called del is created
B. the del class is derived from the MulticastDelegate class
C. the del class will contain a one argument constructor and an invoke() method
D. all of the mentioned
Answer» E.
24.

What does the following code block defines?class Gen { T ob; }

A. Generics class declaration
B. Generic constructor declaration
C. A simple class declaration
D. All of the mentioned
Answer» B. Generic constructor declaration
25.

Which of the following statements are correct about the delegate declaration given below?delegate void del(int i);1. On declaring the delegate a class called del will get created.2. The signature of del need not be same as the signature of the method that we intend to call using it.3. The del class will be derived from the MulticastDelegate class.4. The method that can be called using del should not be a static method.5. The del class will contain a one-argument constructor and an lnvoke() method.

A. 1, 2 and 3 only
B. 1, 3 and 5 only
C. 2 and 4 only
D. 4 only
Answer» C. 2 and 4 only
26.

In which of the following areas are delegates commonly used?1. Remoting2. Serialization3. File Input/Output4. Multithreading5. Event handling

A. 1 and 2 only
B. 1 and 5 only
C. 1, 2 and 3 only
D. 4 and 5 only
Answer» E.
27.

Which of the following statements are correct about a delegate?1. Inheritance is a prerequisite for using delegates.2. Delegates are type-safe.3. Delegates provide wrappers for function pointers.4. The declaration of a delegate must match the signature of the method that we intend to call using it.5. Functions called using delegates are always late-bound.

A. 1 and 2 only
B. 1, 2 and 3 only
C. 2, 3 and 4 only
D. All of the above
Answer» D. All of the above
28.

Which of the following statements are correct about delegates?1. Delegates are not type-safe.2. Delegate is a user-defined type.3. Only one method can be bound with one delegate object. 4. Delegates can be used to implement callback notification.5. Delegates permit execution of a method on a secondary thread in an asynchronous manner.

A. 1 and 2 only
B. 1, 2 and 3 only
C. 2, 4 and 5 only
D. 4 and 5 only
Answer» D. 4 and 5 only