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 are NOT true about .NET Framework?
  1. It provides a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.
  2. It provides a code-execution environment that minimizes software deployment and versioning conflicts.
  3. It provides a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party.
  4. It provides different programming models for Windows-based applications and Web-based applications.
  5. It provides an event driven programming model for building Windows Device Drivers.
1, 2
2, 4
4, 5
1, 2, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
What will be the output of the following code snippet when it is executed?
    int x = 1; 
    float y = 1.1f;
    short z = 1;
    Console.WriteLine((float) x + y * z - (x += (short) y));
0.1
1.0
1.1
11
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.

Which of the following statement correctly assigns a value 33 to a variable c?

byte a = 11, b = 22, c;
c = (byte) (a + b);
c = (byte) a + (byte) b;
c = (int) a + (int) b;
c = (int)(a + b);
c = a + b;
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified?
float pi = 3.14F;
#define pi 3.14F;
const float pi = 3.14F;
const float pi; pi = 3.14F;
pi = 3.14F;
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.

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

6.
Which of the following loop correctly prints the elements of the array?
char[ ] arr = new char[ ] {'k', 'i','C', 'i','t'} ;
do
{
    Console.WriteLine((char) i); 
} 
while (int i = 0; i < arr; i++);
foreach (int i in arr)
{
    Console.WriteLine((char) i);
}
for (int i = 0; i < arr; i++)
{
    Console.WriteLine((char) i);
}
while (int i = 0; i < arr; i++)
{
    Console.WriteLine((char) i);
}
do
{
    Console.WriteLine((char) i); 
} 
until (int i = 0; i < arr; i++);
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

8.
Which of the following statements is correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        public int index; 
        public int[] arr = new int[10]; 
        
        public void fun(int i, int val)
        { 
            arr[i] = val;
        }
    }
     
    class MyProgram
    { 
        static void Main(string[] args)
        {
            Sample s = new Sample(); 
            s.index = 20; 
            Sample.fun(1, 5); 
            s.fun(1, 5); 
        } 
    } 
}
s.index = 20 will report an error since index is public.
The call s.fun(1, 5) will work correctly.
Sample.fun(1, 5) will set a value 5 in arr[ 1 ].
The call Sample.fun(1, 5) cannot work since fun() is not a shared function.
arr being a data member, we cannot declare it as public.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
    class SampleProgram
    {
        static void Main(string[ ] args)
        {
            string str= "Hello World!";
            Console.WriteLine( String.Compare(str, "Hello World?" ).GetType() );
        }
    }
}
0
1
String
Hello World?
System.Int32
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following are true about classes and struct?
  1. A class is a reference type, whereas a struct is a value type.
  2. Objects are created using new, whereas structure variables can be created either using new or without using new.
  3. A structure variable will always be created slower than an object.
  4. A structure variable will die when it goes out of scope.
  5. An object will die when it goes out of scope.
1, 2, 4
3, 5
2, 4
3, 4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following is the correct way to define a variable of the type struct Emp declared below?
struct Emp
{
    private String name; 
    private int age; 
    private Single sal;
}
  1. Emp e(); e = new Emp();
  2. Emp e = new Emp;
  3. Emp e; e = new Emp;
  4. Emp e = new Emp();
  5. Emp e;
1, 3
2, 5
4, 5
1, 2, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Which of the following is the correct way to call subroutine MyFun() of the Sample class given below?
class Sample
{
    public void MyFun(int i, Single j)
    {
        Console.WriteLine("Welcome to IndiaBIX !");
    }
}
delegate void del(int i);
Sample s = new Sample();
del d = new del(ref s.MyFun);
d(10, 1.1f);
delegate void del(int i, Single j);
del d;
Sample s = new Sample();
d = new del(ref s.MyFun);
d(10, 1.1f);
Sample s = new Sample();
delegate void d = new del(ref MyFun);
d(10, 1.1f);
delegate void del(int i, Single]);
Sample s = new Sample();
del = new delegate(ref MyFun);
del(10, 1.1f);
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statements is correct about the C#.NET code snippet given below?
int a = 10; 
int b = 20; 
int c = 30;
enum color: byte
{
    red = a, 
    green = b,
    blue = c 
}
Variables cannot be assigned to enum elements.
Variables can be assigned to any one of the enum elements.
Variables can be assigned only to the first enum element.
Values assigned to enum elements must always be successive values.
Values assigned to enum elements must always begin with 0.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
In a HashTable Key cannot be null, but Value can be.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following statements are correct about a namespace used in C#.NET?
  1. Classes must belong to a namespace, whereas structures need not.
  2. Every class, struct, enum, delegate and interlace has to belong to some or the other namespace.
  3. All elements of the namespace have to belong to one file.
  4. If not mentioned, a namespace takes the name of the current project.
  5. The namespace should be imported to be able to use the elements in it.
1, 3
2, 4, 5
3, 5
4 only
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following is NOT a namespace in the .NET Framework Class Library?
System.Process
System.Security
System.Threading
System.Drawing
System.Xml
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following C#.NET code snippets will correctly print "Hello C#.NET"?
import System; 
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[] args)
        { 
            Console.WriteLine("Hello C#.NET");
        } 
    } 
}
using System;
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            WriteLine("Hello C#.NET");
        } 
    } 
}
using System.Console; 
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            WriteLine("Hello C#.NET");
        } 
    } 
}
using System;
namespace IndiabixConsoleApplication
{ 
    class MyProgram
    { 
        static void Main(string[] args)
        { 
            Console.WriteLine("Hello C#.NET");
        }
    }
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following is NOT an Exception?
StackOverflow
Division By Zero
Insufficient Memory
Incorrect Arithmetic Expression
Arithmetic overflow or underflow
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
In C#.NET if we do not catch the exception thrown at runtime then which of the following will catch it?
Compiler
CLR
Linker
Loader
Operating system
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?
12 bytes
24 bytes
0 byte
8 bytes
16 bytes
Your Answer: Option
(Not Answered)
Correct Answer: Option

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