Online C# Programming Test - C# Programming Test 1

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 utilities can be used to compile managed assemblies into processor-specific native code?
gacutil
ngen
sn
dumpbin
ildasm
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following are value types?
  1. Integer
  2. Array
  3. Single
  4. String
  5. Long
1, 2, 5
1, 3, 5
2, 4
3, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following are the correct way to initialise the variables i and j to a value 10 each?
  1. int i = 10; int j = 10;
  2. int i, j;
    i = 10 : j = 10;
  3. int i = 10, j = 10;
  4. int i, j = 10;
  5. int i = j = 10;
2, 4
1, 3
3, 5
4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
What is the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
    public enum color
    { red, green, blue };
    
    class SampleProgram
    {
        static void Main (string[ ] args)
        {
            color c = color.blue;
            switch (c)
            {
                case color.red:
                    Console.WriteLine(color.red); 
                    break; 
                
                case color.green: 
                    Console.WriteLine(color.green); 
                    break; 
                
                case color.blue: 
                    Console.WriteLine(color.blue); 
                    break; 
            } 
        } 
    } 
}
red
blue
0
1
2
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
What will be the output of the C#.NET code snippet given below?
int i = 2, j = i;
if (Convert.ToBoolean((i | j & 5) & (j - 25 * 1)))
    Console.WriteLine(1); 
else
    Console.WriteLine(0);
0
1
Compile Error
Run time Error
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
In which of the following should the methods of a class differ if they are to be treated as overloaded methods?
  1. Type of arguments
  2. Return type of methods
  3. Number of arguments
  4. Names of methods
  5. Order of arguments
2, 4
3, 5
1, 3, 5
3, 4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B?
While creating the object firstly the constructor of class B will be called followed by constructor of class A.
While creating the object firstly the constructor of class A will be called followed by constructor of class B.
The constructor of only class B will be called.
The constructor of only class A will be called.
The order of calling constructors depends upon whether constructors in class A and class B are private or public.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
How can you prevent inheritance from a class in C#.NET ?
Declare the class as shadows.
Declare the class as overloads.
Declare the class as sealed.
Declare the class as suppress.
Declare the class as override.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
C#.NET allows sealed attribute to be used as a part of class statement. Classes declared with sealed keyword cannot be used as based class for other classes. Most important reason to do this world be to prevent behavior of a class to be changed in any way.

9.
If s1 and s2 are references to two strings then which of the following are the correct ways to find whether the contents of the two strings are equal?
  1. if(s1 = s2)
  2. if(s1 == s2)
  3. int c;
    c = s1.CompareTo(s2);
  4. if( strcmp(s1, s2) )
  5. if (s1 is s2)
1, 2
2, 3
4, 5
3, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following statements are correct about delegates?
Delegates cannot be used to call a static method of a class.
Delegates cannot be used to call procedures that receive variable number of arguments.
If signatures of two methods are same they can be called through the same delegate object.
Delegates cannot be used to call an instance function. Delegates cannot be used to call an instance subroutine.
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following forms of applying an attribute is correct?
< Serializable() > class sample
{ /* ... */ }
(Serializable()) class sample
{ /* ... */ }
[ Serializable() ] class sample
{ /* ... */ }
Serializablef) class sample
{ /* ... */ }
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Once applied which of the following CANNOT inspect the applied attribute?
CLR
Linker
ASP.NET Runtime
Visual Studio.NET
Language compilers
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following is the correct output for the C#.NET code snippet given below?
enum color: int
{ 
    red,
    green, 
    blue = 5, 
    cyan,
    magenta = 10, 
    yellow 
}
Console.Write( (int) color.green + ", " ); 
Console.Write( (int) color.yellow );
2, 11
1, 11
2, 6
1, 5
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?
Declare rollNo property with both get and set accessors.
Declare rollNo property with only set accessor.
Declare rollNo property with get, set and normal accessors.
Declare rollNo property with only get accessor.
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following is the correct way to implement a read only property Length in a Sample class?
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
    } 
}
class Sample
{
    public int Length
    {
        get
        {
            return Length;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
        set
        {
            len = value;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        Readonly get
        {
            return len;
        } 
    } 
}
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
If a namespace is present in a library then which of the following is the correct way to use the elements of the namespace?
Add Reference of the namespace.
Use the elements of the namespace.
Add Reference of the namespace.
Import the namespace.
Use the elements of the namespace.
Import the namespace.
Use the elements of the namespace.
Copy the library in the same directory as the project that is trying to use it.
Use the elements of the namespace.
Install the namespace in Global Assembly Cache.
Use the elements of the namespace.
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
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

18.
Which of the following statements are correct about exception handling in C#.NET?
  1. try blocks cannot be nested.
  2. In one function, there can be only one try block.
  3. An exception must be caught in the same function in which it is thrown.
  4. All values set up in the exception object are available in the catch block.
  5. While throwing a user-defined exception multiple values can be set in the exception, object.
1 only
1 and 2 only
3 only
4 and 5 only
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
True
False
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following unary operators can be overloaded?
  1. true
  2. false
  3. +
  4. new
  5. is
1, 2, 3
3, 4, 5
3 only
5 only
Your Answer: Option
(Not Answered)
Correct Answer: Option

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