Online C# Programming Test - C# Programming Test - Random

Instruction:

  • This is a FREE online test. Beware of scammers who ask for money to attend this test.
  • Total number of questions: 20.
  • Time allotted: 30 minutes.
  • Each question carries 1 mark; there are no negative marks.
  • DO NOT refresh the page.
  • All the best!

Marks : 2/20


Total number of questions
20
Number of answered questions
0
Number of unanswered questions
20
Test Review : View answers and explanation for this test.

1.
Which of the following jobs are done by Common Language Runtime?
  1. It provides core services such as memory management, thread management, and remoting.
  2. It enforces strict type safety.
  3. It provides Code Access Security.
  4. It provides Garbage Collection Services.
Only 1 and 2
Only 3, 4
Only 1, 3 and 4
Only 2, 3 and 4
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.

Which of the following statements is correct about the C#.NET code snippet given below?

short s1 = 20;
short s2 = 400;
int a;
a = s1 * s2;
A value 8000 will be assigned to a.
A negative value will be assigned to a.
During arithmetic if the result exceeds the high or low value of the range the value wraps around till the other side of the range.
An error is reported as widening conversion cannot takes place.
An overflow error will be reported since the result of the multiplication exceeds the range of a Short Integer.
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following statements is correct about the C#.NET code snippet given below?
switch (id)
{
    case 6: 
        grp = "Grp B"; 
        break;
    
    case 13:
        grp = "Grp D";
        break;
    
    case 1:
        grp = "Grp A";
        break;
    
    case ls > 20:
        grp = "Grp E";
        break ;
    
    case Else:
        grp = "Grp F";
        break;
}
Compiler will report an error in case ls > 20 as well as in case Else.
There is no error in this switch case statement.
Compiler will report an error only in case Else.
Compiler will report an error as there is no default case.
The order of the first three cases should be case 1, case 6, case 13 (ascending).
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Suppose n is a variable of the type Byte and we wish to put OFF its fourth bit (from right) without disturbing any other bits. Which of the following statements will do this correctly?
n = n && HF7
n = n & 16
n = n & 0xF7
n = n & HexF7
n = n & 8
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following is NOT an Arithmetic operator in C#.NET?
**
+
/
%
*
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statements are correct about functions used in C#.NET?
  1. Function definitions cannot be nested.
  2. Functions can be called recursively.
  3. If we do not return a value from a function then a value -1 gets returned.
  4. To return the control from middle of a function exit function should be used.
  5. Function calls can be nested.
1, 2, 5
2, 3, 5
2, 3
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            int i = 5;
            int j;
            fun1(ref i);
            fun2(out j);
            Console.WriteLine(i + ", " + j);
        }
        static void funl(ref int x)
        {
            x = x * x;
        }
        static void fun2(out int x)
        {
            x = 6; 
            x = x * x; 
        }
    }
}
5, 6
5, 36
25, 36
25, 0
5, 0
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
If a function fun() is to receive an int, a Single & a double and it is to return a decimal then which of the following is the correct way of defining this function?
decimal static fun(int i, Single j, double k)
{ ... }
decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k)
{ ... }
static decimal fun(int i, Single j, double k) decimal
{ ... }
static fun(int i, Single j, double k)
{ 
    ... 
    return decimal;
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Is it possible for you to prevent an object from being created by using zero argument constructor?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following snippets are the correct way to convert a Single into a String?
  1. Single f = 9.8f; 
    String s;
    s = (String) (f);
  2. Single f = 9.8f; 
    String s;
    s = Convert.ToString(f);
  3. Single f = 9.8f; 
    String s;
    s = f.ToString();
  4. Single f = 9.8f; 
    String s;
    s = Clnt(f);
  5. Single f = 9.8f; 
    String s;
    s = CString(f);
1, 2
2, 3
1, 3, 5
2, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements about a String is correct?
A String is created on the stack.
Whether a String is created on the stack or the heap depends on the length of the String.
A String is a primitive.
A String can be created by using the statement String s1 = new String;
A String is created on the heap.
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Suppose a Generic class called SortObjects is to be made capable of sorting objects of any type (Integer, Single, Byte etc.). Which of the following programming constructs should be used to implement the comparision function?
Namespace
Interface
Encapsulation
Delegate
Attribute
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following correctly describes the contents of the filename AssemblyInfo.cs?
It contains method-level attributes.
It contains class-level attributes.
It contains assembly-level attributes.
It contains structure-level attributes.
It contains namespace-level attributes.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
For the code snippet given below, which of the following statements are valid?
public class MyContainer<T> 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.
1 and 2 Only
3 and 4 Only
2 and 3 Only
All of the above
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following is the correct output for the C#.NET code snippet given below?
enum color
{
    red,
    green,
    blue 
}
color c = color.red;
Type t;
t = c.GetType();
string[ ]str;
str = Enum.GetNames(t);
Console.WriteLine(str[ 0 ]);
red
0
1
-1
color.red
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following is NOT an interface declared in System.Collections namespace?
IComparer
IEnumerable
IEnumerator
IDictionaryComparer
IDictionaryEnumerator
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Suppose value of the Capacity property of ArrayList Collection is set to 4. What will be the capacity of the Collection on adding fifth element to it?
4
8
16
32
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
If ListBox is class present in System.Windows.Forms namespace, then which of the following statements are the correct way to create an object of ListBox Class?
  1. using System.Windows.Forms; 
    ListBox lb = new ListBox();
  2. using LBControl = System.Windows.Forms;
    LBControl lb = new LBControl();
  3. System.Windows.Forms.ListBox lb = new System.Windows.Forms.ListBox();
  4. using LBControl lb = new System.Windows.Forms.ListBox;
  5. using LBControl = System.Windows.Forms.ListBox; 
    LBControl lb = new LBControl();
1, 3
2, 4, 5
1, 3, 5
5 only
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Which of the following is the Object Oriented way of handling run-time errors?
OnError
HERESULT
Exceptions
Error codes
Setjump and Longjump
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following keyword is used to overload user-defined types by defining static member functions?
op
opoverload
operator
operatoroverload
udoperator
Your Answer: Option
(Not Answered)
Correct Answer: Option

*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here: