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 benefits do we get on running managed code under CLR?
  1. Type safety of the code running under CLR is assured.
  2. It is ensured that an application would not access the memory that it is not authorized to access.
  3. It launches separate process for every application running under it.
  4. The resources are Garbage collected.
Only 1 and 2
Only 2, 3 and 4
Only 1, 2 and 4
Only 4
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following statements are correct?
  1. We can assign values of any type to variables of type object.
  2. When a variable of a value type is converted to object, it is said to be unboxed.
  3. When a variable of type object is converted to a value type, it is said to be boxed.
  4. Boolean variable cannot have a value of null.
  5. When a value type is boxed, an entirely new object must be allocated and constructed.
2, 5
1, 5
3, 4
2, 3
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following statements are correct?
  1. The switch statement is a control statement that handles multiple selections and enumerations by passing control to one of the case statements within its body.
  2. The goto statement passes control to the next iteration of the enclosing iteration statement in which it appears.
  3. Branching is performed using jump statements which cause an immediate transfer of the program control.
  4. A common use of continue is to transfer control to a specific switch-case label or the default label in a switch statement.
  5. The do statement executes a statement or a block of statements enclosed in {} repeatedly until a specified expression evaluates to false.
1, 2, 4
1, 3, 5
2, 3, 4
3, 4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
If a procedure 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 procedure?
fun(int i, Single j, double k) decimal 
{ ... }
static decimal fun(int i, Single j, double k) 
{ ... }
fun(int i, Single j, double k) 
{
    ...
    return decimal; 
}
static decimal fun(int i, Single j, double k) decimal 
{ ... }
A procedure can never return a value.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

6.
Which of the following statements are correct about constructors in C#.NET?
  1. Constructors cannot be overloaded.
  2. Constructors always have the name same as the name of the class.
  3. Constructors are never called explicitly.
  4. Constructors never return any value.
  5. Constructors allocate space for the object in memory.
1, 3, 5
2, 3, 4
3, 5
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following are the correct ways to define an array of 2 rows and 3 columns?
  1. int[ , ] a;
    a = new int[2, 3]{{7, 1, 3},{2, 9, 6}};
  2. int[ , ] a;
    a = new int[2, 3]{};
  3. int[ , ] a = {{7, 1, 3}, {2, 9,6 }};
  4. int[ , ] a;
    a = new int[1, 2];
  5. int[ , ] a;
    a = new int[1, 2]{{7, 1, 3}, {2, 9, 6}};
1, 2 , 3
1, 3
2, 3
2, 4, 5
4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following statements are correct about the C#.NET code snippet given below?
    int[] a = {11, 3, 5, 9, 4}; 
  1. The array elements are created on the stack.
  2. Refernce a is created on the stack.
  3. The array elements are created on the heap.
  4. On declaring the array a new array class is created which is derived from System.Array Class.
  5. Whether the array elements are stored in the stack or heap depends upon the size of the array.
1, 2
2, 3, 4
2, 3, 5
4, 5
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements are correct?
  1. String is a value type.
  2. String literals can contain any character literal including escape sequences.
  3. The equality operators are defined to compare the values of string objects as well as references.
  4. Attempting to access a character that is outside the bounds of the string results in an IndexOutOfRangeException.
  5. The contents of a string object can be changed after the object is created.
1, 3
3, 5
2, 4
1, 2, 4
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following statements are correct about the structure declaration given below?
struct Book
{
    private String name; 
    protected int totalpages; 
    public Single price; 
    public void Showdata()
    {
        Console.WriteLine(name + " " + totalpages + " " + price);
    } 
    Book()
    {
        name = " "; 
        totalpages = 0;
        price = 0.0f; 
    } 
} 
Book b = new Book();
  1. We cannot declare the access modifier of totalpages as protected.
  2. We cannot declare the access modifier of name as private.
  3. We cannot define a zero-argument constructor inside a structure.
  4. We cannot declare the access modifier of price as public.
  5. We can define a Showdata() method inside a structure.
1, 2
1, 3, 5
2, 4
3, 4, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

12.
Which of the following are the correct ways to declare a delegate for calling the function func() defined in the sample class given below?
class Sample
{
    public int func(int i, Single j)
    {
        /* Add code here. */
    }
}
delegate d(int i, Single j);
delegate void d(int, Single);
delegate int d(int i, Single j);
delegate void (int i, Single j);
delegate int sample.func(int i, Single j);
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statements are correct about inspecting an attribute in C#.NET?
  1. An attribute can be inspected at link-time.
  2. An attribute can be inspected at compile-time.
  3. An attribute can be inspected at run-time.
  4. An attribute can be inspected at design-time.
1, 2
3, 4
1, 3, 4
All of the above
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following is the correct way to find out the number of elements currently present in an ArrayList Collection called arr?
arr.Count
arr.GrowSize
arr.MaxIndex
arr.Capacity
arr.UpperBound
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

16.
Which of the following statements are correct about a HashTable collection?
  1. It is a keyed collection.
  2. It is a ordered collection.
  3. It is an indexed collection.
  4. It implements a IDictionaryEnumerator interface in its inner class.
  5. The key - value pairs present in a HashTable can be accessed using the Keys and Values properties of the inner class that implements the IDictionaryEnumerator interface.
1 and 2 only
1, 2 and 3 only
4 and 5 only
1, 4 and 5 only
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
If Sample class has a Length property with get and set accessors then which of the following statements will work correctly?
  1. Sample.Length = 20;
  2. Sample m = new Sample(); 
    m.Length = 10;
  3. Console.WriteLine(Sample.Length);
  4. Sample m = new Sample(); 
    int len;
    len = m.Length;
  5. Sample m = new Sample(); 
    m.Length = m.Length + 20;
1, 3
2, 4, 5
4 only
3, 5
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

19.
A derived class can stop virtual inheritance by declaring an override as
inherits
extends
inheritable
not inheritable
sealed
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
Which of the following is the correct way to implement the interface given below?
interface IPerson
{ 
    String FirstName
    {
        get;
        set; 
    } 
}
class Employee : IPerson
{
    private String str; 
    public String FirstName
    {
        get
        { 
            return str;
        } 
        set
        { 
            str = value;
        } 
    } 
}
class Employee
{
    private String str;
    public String IPerson.FirstName
    { 
        get
        { 
            return str;
        } 
        set
        { 
            str = value;
        } 
    } 
}
class Employee : implements IPerson
{
    private String str; 
    public String FirstName
    { 
        get
        { 
            return str;
        } 
        set
        {
            str = value; 
        } 
    } 
}
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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