C# .Net Practice Test For Your Campus Drive

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Cvktech
C
Cvktech
Community Contributor
Quizzes Created: 10 | Total Attempts: 42,521
Questions: 20 | Attempts: 167

SettingsSettingsSettings
C# .Net Practice Test For Your Campus Drive - Quiz

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

    Correct Answer
    A. Config files
    Explanation
    The best way to store connection strings is in config files. Config files provide a centralized location for storing application settings, including connection strings. Storing connection strings in config files allows for easy access and modification without the need to modify the application code. Additionally, config files can be encrypted to enhance security and protect sensitive information. This approach promotes flexibility and maintainability, making it the preferred method for storing connection strings.

    Rate this question:

  • 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

    Correct Answer
    A. 1, 2, 3
    Explanation
    An assembly is the smallest deployable unit in .NET. It can contain multiple entry points, such as Main(), WinMain(), or DLLMain(). An assembly can be either a Shared assembly, which can be accessed by multiple applications, or a Private assembly, which is specific to a single application. The statement that an assembly can contain only code and data is incorrect, as it can also include resources such as images and configuration files. The statement that an assembly is always in the form of an EXE file is also incorrect, as it can also be in the form of a DLL file.

    Rate this question:

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

    Correct Answer
    C. Func() cannot be considered overloaded because: return value cannot be used to distinguish between two overloaded functions.
    Explanation
    The return value of a function cannot be used to distinguish between two overloaded functions. In this code snippet, the function func() is defined twice with different return types (int and Single). However, this is not considered as overloading because the return value cannot be used to differentiate between the two functions.

    Rate this question:

  • 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);

    Correct Answer
    D. Sample s3 = new Sample(10, 1.2f, 2.4);
    Explanation
    The correct answer is Sample s3 = new Sample(10, 1.2f, 2.4). This is because the Sample class has a constructor that takes three arguments: an int, a Single, and a double. In this answer choice, all three arguments are provided, matching the constructor's parameter types. Therefore, this is the correct way to create an object of the Sample class. The other answer choices do not provide the correct number or types of arguments for the constructor, so they will not work correctly.

    Rate this question:

  • 5. 

    Can static procedures access instance data?

    • A.

      Yes

    • B.

      No

    • C.

      Some times it's True

    Correct Answer
    B. No
    Explanation
    Static procedures cannot access instance data because instance data belongs to a specific instance of a class, whereas static procedures are associated with the class itself and do not have access to instance-specific data. Static procedures can only access static data and perform operations that are not specific to any particular instance.

    Rate this question:

  • 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

    Correct Answer
    A. Sample class Bix1 method
    Explanation
    The output of the code snippet will be "Sample class Bix1 method". This is because the static constructor in the Sample class is called before any other code in the class is executed. The static constructor prints "Sample class". Then, the Main method in the MyProgram class calls the Bix1 method in the Sample class, which prints "Bix1 method". Therefore, the final output is "Sample class Bix1 method".

    Rate this question:

  • 7. 

    Once applied which of the following CANNOT inspect the applied attribute?

    • A.

      CLR

    • B.

      Linker

    • C.

      ASP.NET Runtime

    • D.

      Visual Studio.NET

    Correct Answer
    B. Linker
    Explanation
    The linker is responsible for combining object files and libraries to create an executable or a DLL. Its main task is to resolve external references and generate the final executable code. Once the linker has finished its job, it does not have the ability to inspect the applied attribute. The CLR (Common Language Runtime) is the execution engine of .NET, responsible for executing managed code. ASP.NET Runtime is a component of the CLR that specifically handles ASP.NET applications. Visual Studio.NET is an integrated development environment (IDE) used for creating, debugging, and deploying applications.

    Rate this question:

  • 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") >

    Correct Answer
    B. [ assembly : AssemblyDescription("DCube Component Library") ]
    Explanation
    The correct way to apply an attribute to an Assembly is by using the syntax "[assembly: AssemblyDescription("DCube Component Library") ]". This syntax is the correct format for applying an attribute to an Assembly in C#.

    Rate this question:

  • 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

    Correct Answer
    C. 20 16 12 8 4 0 -4 -8 -12
    Explanation
    The correct output for the given C#.NET program is "20 16 12 8 4 0 -4 -8 -12".


    The program initializes the variable i to 20. Then, it enters a for loop with no initialization or condition, indicating an infinite loop. Inside the loop, it prints the value of i followed by a space.

    The loop continues until the value of i is less than -10. In each iteration, the value of i is decreased by 4 using the statement i -= 4.

    Therefore, the output will be a sequence of numbers starting from 20 and decreasing by 4 in each iteration until it reaches -12.

    Rate this question:

  • 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

    Correct Answer
    B. Int i; for (i = 0; i
    Explanation
    The correct way to rewrite the given C#.NET code snippet is to use a for loop. The correct answer suggests initializing the variable 'i' outside the loop, and using a for loop with the condition 'i

    Rate this question:

  • 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".

    Correct Answer
    A. The compiler will report case i and case j as errors since variables cannot be used in cases.
    Explanation
    The correct answer is that the compiler will report case i and case j as errors since variables cannot be used in cases. This is because in a switch case statement in C#, the cases must be constant values, not variables. In this code snippet, the variables i and j are used as cases, which is not allowed and will result in a compilation error.

    Rate this question:

  • 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

    Correct Answer
    D. Fibonacci
    Explanation
    The given C#.NET code snippet generates a Fibonacci number series as output. It starts with initializing two variables i and j as 1. It then enters a while loop where it prints the value of j and calculates the next value in the series by adding i and j. It then assigns the value of j to i and the calculated value to j. This process continues until i becomes greater than or equal to 25. Therefore, the output of this code snippet will be a Fibonacci number series.

    Rate this question:

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

    Correct Answer
    C. Objects are always nameless.
    Explanation
    In C#.NET, objects are not always nameless. Objects are instances of classes and can be assigned names or references. The statement "Objects are always nameless" is incorrect.

    Rate this question:

  • 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

    Correct Answer
    A. 2
    Explanation
    The code snippet creates a jagged array `a` with 2 rows. The first row has 4 elements {6, 1, 4, 3} and the second row has 3 elements {9, 2, 7}. The `GetUpperBound(0)` method is used to get the upper bound of the first dimension (rows) of the array `a`. Since the first dimension is 0-based, the upper bound will be 1. Therefore, the correct output of the code is 1.

    Rate this question:

  • 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

    Correct Answer
    A. 0 0 34 34
    Explanation
    The code snippet initializes a 2D array "arr" with dimensions 2x2 and fills it with values using nested for loops. The values are calculated using the formula i * 17 + i * 17, where i represents the row index. The values are then printed using Console.Write(). The output will be "0 0 34 34", as the first row will have values 0 and 0, and the second row will have values 34 and 34.

    Rate this question:

  • 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

    Correct Answer
    C. 2 and 5 only
    Explanation
    If an exception occurs, the program does not necessarily terminate abruptly without a chance to recover. The program can use exception handling to catch and handle exceptions, allowing it to continue running. The statement in option 2 is correct, as the finally clause will always get executed, regardless of whether an exception occurs or not. Option 1 is incorrect. Option 3 is not mentioned in the given statements. Option 4 is incorrect, as the finally clause is written inside the try block. Option 5 is correct, as the finally clause is commonly used for clean up operations like closing connections.

    Rate this question:

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

    Correct Answer
    D. It will output: Exception occurred Remaining program.
    Explanation
    The given C#.NET program prompts the user to enter a number and tries to assign the value 66 to the corresponding index in an array. If the user inputs a number that is out of the array's bounds, an exception will occur and the program will output "Exception occurred". Regardless of whether an exception occurs or not, the program will also output "Remaining program". Therefore, the correct statement is "It will output: Exception occurred Remaining program."

    Rate this question:

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

    Correct Answer
    D. They use efficient algorithms to manage the collection, thereby improving the performance of the program.
    Explanation
    The statement "They use efficient algorithms to manage the collection, thereby improving the performance of the program" is correct. This means that the collection classes in the Framework Class Library are designed to use optimized algorithms for managing collections, resulting in better performance of the program.

    Rate this question:

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

    Correct Answer
    A. Program will compile and on execution will print: IndiaBIX 4.2
    Explanation
    The given code snippet defines a class called TestIndiaBix with a generic method called TestSub. The method takes a parameter of type M and prints it. In the Main method, an instance of TestIndiaBix is created and the TestSub method is called twice, once with a string argument "IndiaBIX " and once with a float argument 4.2f. Since the TestSub method is generic, it can accept arguments of any type, so the program will compile successfully. On execution, it will print "IndiaBIX 4.2" as the output.

    Rate this question:

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

    Correct Answer
    A. It will print string "Hello" on the console.
    Explanation
    The code snippet creates an instance of the Generic class with type parameter String. It then assigns the value "Hello" to the Field member of the Generic instance and prints it to the console. Therefore, the statement "It will print string 'Hello' on the console" is valid.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 12, 2012
    Quiz Created by
    Cvktech
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.