C# .Net Practice Test For Your Campus Drive

20 Questions | Total Attempts: 51

Settings
Please wait...
C# .Net Practice Test For Your Campus Drive

This is a C#. Net practice test for your campus drive and it is to test your prowess when it comes to this program. C# is a strong Object-Oriented programming language that is mostly built on the. NET framework. Genereally used by the Visual Studio Community, it allows them to create both paid for and free applications in the field. Take up this test and see how well you understand the language.


Questions and Answers
  • 1. 
    What is the best way to store the connection strings?
    • A. 

      Config files

    • B. 

      Database

    • C. 

      Text file

    • D. 

      Session

  • 2. 
    Which of the following statements are correct about a .NET Assembly?
    1. It is the smallest deployable unit.
    2. Each assembly has only one entry point - Main(), WinMain() or DLLMain().
    3. An assembly can be a Shared assembly or a Private assembly.
    4. An assembly can contain only code and data.
    5. An assembly is always in the form of an EXE file.
    • A. 

      1, 2, 3

    • B. 

      2, 4, 5

    • C. 

      1, 3, 5

    • D. 

      1, 2

  • 3. 
    Which of the following statements is correct about the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class Sample { public int func() { return 1; } public Single func() { return 2.4f ; } } class Program { static void Main(string[ ] args) { Sample s1 = new Sample(); int i; i = s1.func(); Single j; j = s1.func(); } } }
    • A. 

      Func() is a valid overloaded function.

    • B. 

      Overloading works only in case of subroutines and not in case of functions.

    • C. 

      Func() cannot be considered overloaded because: return value cannot be used to distinguish between two overloaded functions.

    • D. 

      The call to i = s1.func() will assign 1 to i.

  • 4. 
    Which of the following ways to create an object of the Sample class given below will work correctly? class Sample { int i; Single j; double k; public Sample (int ii, Single jj, double kk) { i = ii; j = jj; k = kk; } }
    • A. 

      Sample s1 = new Sample();

    • B. 

      Sample s1 = new Sample(10);

    • C. 

      Sample s2 = new Sample(10, 1.2f);

    • D. 

      Sample s3 = new Sample(10, 1.2f, 2.4);

  • 5. 
    Can static procedures access instance data?
    • A. 

      Yes

    • B. 

      No

    • C. 

      Some times it's True

  • 6. 
      What will be the output of the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class Sample { static Sample() { Console.Write("Sample class "); } public static void Bix1() { Console.Write("Bix1 method "); } } class MyProgram { static void Main(string[ ] args) { Sample.Bix1(); } } }
    • A. 

      Sample class Bix1 method

    • B. 

      Bix1 method

    • C. 

      Sample class

    • D. 

      Bix1 method Sample class

  • 7. 
    Once applied which of the following CANNOT inspect the applied attribute?
    • A. 

      CLR

    • B. 

      Linker

    • C. 

      ASP.NET Runtime

    • D. 

      Visual Studio.NET

  • 8. 
    Which of the following is the correct way to apply an attribute to an Assembly?
    • A. 

      [ AssemblyDescription("DCube Component Library") ]

    • B. 

      [ assembly : AssemblyDescription("DCube Component Library") ]

    • C. 

      [ Assemblylnfo : AssemblyDescription("DCube Component Library") ]

    • D. 

      < Assembly: AssemblyDescription("DCube Component Library") >

  • 9. 
    Which of the following is the correct output for the C#.NET program given below? int i = 20 ; for( ; ; ) { Console.Write(i + " "); if (i >= -10) i -= 4; else break; }
    • A. 

      20 16 12 84 0 -4 -8

    • B. 

      20 16 12 8 4 0

    • C. 

      20 16 12 8 4 0 -4 -8 -12

    • D. 

      16 12 8 4 0

  • 10. 
    Which of the following is the correct way to rewrite the following C#.NET code snippet given below? int i = 0; do { Console.WriteLine(i); i+ = 1; } while (i <= 10);
    • A. 

      Int i = 0; do { Console.WriteLine(i); } until (i

    • B. 

      Int i; for (i = 0; i

    • C. 

      Int i = 0; while (i

    • D. 

      Int i = 0; do while ( i

  • 11. 
    Which of the following statements is correct about the C#.NET code snippet given below? int i, j, id = 0; switch (id) { case i: Console.WriteLine("I am in Case i"); break; case j: Console.WriteLine("I am in Case j"); break; }
    • A. 

      The compiler will report case i and case j as errors since variables cannot be used in cases.

    • B. 

      The compiler will report an error since there is no default case in the switch case statement.

    • C. 

      The code snippet prints the result as "I am in Case i".

    • D. 

      The code snippet prints the result as "I am in Case j".

  • 12. 
    The C#.NET code snippet given below generates ____ numbers series as output? int i = 1, j = 1, val; while (i < 25) { Console.Write(j + " "); val = i + j; j = i; i = val; }
    • A. 

      Prime

    • B. 

      Palindrome

    • C. 

      Odd

    • D. 

      Fibonacci

  • 13. 
    Which of the following statements is correct about classes and objects in C#.NET?
    • A. 

      Class is a value type.

    • B. 

      Since objects are typically big in size, they are created on the stack.

    • C. 

      Objects are always nameless.

    • D. 

      All the above.

  • 14. 
    Which of the following is the correct output of the C#.NET code snippet given below? int[][] a = new int[2][]; a[0] = new int[4]{6, 1, 4, 3}; a[1] = new int[3]{9, 2, 7}; Console.WriteLine(a[1].GetUpperBound(0));
    • A. 

      2

    • B. 

      6

    • C. 

      4

    • D. 

      7

  • 15. 
    What will be the output of the C#.NET code snippet given below? namespace IndiabixConsoleApplication { class SampleProgram { static void Main(string[ ] args) { int i, j; int[ , ] arr = new int[ 2, 2 ]; for(i = 0; i < 2; ++i) { for(j = 0; j < 2; ++j) { arr[i, j] = i * 17 + i * 17; Console.Write(arr[ i, j ] + " "); } } } } }
    • A. 

      0 0 34 34

    • B. 

      0 0 17 17

    • C. 

      0 0 0 0

    • D. 

      34 34 0 0

  • 16. 
    Which of the following statements are correct about exception handling in C#.NET?
    1. If an exception occurs then the program terminates abruptly without getting any chance to recover from the exception.
    2. No matter whether an exception occurs or not, the statements in the finally clause (if present) will get executed.
    3. A program can contain multiple finally clauses.
    4. A finally clause is written outside the try block.
    5. finally clause is used to perform clean up operations like closing the network/database connections.
    • A. 

      1 only

    • B. 

      2 only

    • C. 

      2 and 5 only

    • D. 

      None of the above

  • 17. 
    Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it? using System; namespace IndiabixConsoleApplication { class MyProgram { static void Main (string[] args) { int index; int val = 66; int[] a = new int[5]; try { Consote.Write("Enter a number: "); index = Convert.ToInt32(Console.ReadLine()); a[index] = val; } catch(Exception e) { Console.Write("Exception occurred "); } Console.Write("Remaining program "); } }
    • A. 

      It will output: Exception occurred.

    • B. 

      It will output: Remaining program.

    • C. 

      The value 66 will get assigned to a[6].

    • D. 

      It will output: Exception occurred Remaining program.

  • 18. 
    Which of the following statements are correct about the Collection Classes available in Framework Class Library?
    • A. 

      Elements of a collection cannot be transmitted over a network.

    • B. 

      Elements stored in a collection can be retrieved but cannot be modified.

    • C. 

      It is not easy to adopt the existing Collection classes for newtype of objects.

    • D. 

      They use efficient algorithms to manage the collection, thereby improving the performance of the program.

  • 19. 
    For the code snippet shown below, which of the following statements are valid? public class TestIndiaBix { public void TestSub<M> (M arg) { Console.Write(arg); } } class MyProgram { static void Main(string[] args) { TestIndiaBix bix = new TestIndiaBix(); bix.TestSub("IndiaBIX "); bix.TestSub(4.2f); } }
    • A. 

      Program will compile and on execution will print: IndiaBIX 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.

  • 20. 
    For the code snippet given below, which of the following statements is valid? public class Generic<T> { public T Field; } class Program { static void Main(string[ ] args) { Generic<String> g = new Generic<String>(); g.Field = "Hello"; Console.WriteLine(g.Field); } }
    • 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.