C# .Net Practice Test For Your Campus Drive

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Cvktech
C
Cvktech
Community Contributor
Quizzes Created: 10 | Total Attempts: 48,860
| Attempts: 172 | Questions: 20
Please wait...
Question 1 / 20
0 %
0/100
Score 0/100
1. 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;
    } 
}

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.

Submit
Please wait...
About This Quiz
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... see morecreate both paid for and free applications in the field. Take up this test and see how well you understand the language. see less

Personalize your quiz and earn a certificate with your name on it!
2. 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.

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.

Submit
3. What is the best way to store the connection strings?

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.

Submit
4. 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(); 
        } 
    } 
}

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.

Submit
5. Can static procedures access instance data?

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.

Submit
6. 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;
}

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.

Submit
7. Which of the following statements are correct about the Collection Classes available in Framework Class Library?

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.

Submit
8. 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;
}

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.

Submit
9. 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));

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.

Submit
10. 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;
}

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.

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

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.

Submit
12. 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);

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

Submit
13. 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);
    }
}

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.

Submit
14. Once applied which of the following CANNOT inspect the applied attribute?

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.

Submit
15. Which of the following is the correct way to apply an attribute to an Assembly?

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

Submit
16. 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 ] + " ");
                }
            }
        }
    }
}

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.

Submit
17. 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);
    }
}

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.

Submit
18.   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();
        } 
    } 
}

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

Submit
19. Which of the following statements is correct about classes and objects in C#.NET?

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.

Submit
20. 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 ");
        }
    }

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

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following ways to create an object of the Sample class...
Which of the following statements are correct about exception handling...
What is the best way to store the connection strings?
Which of the following statements is correct about the C#.NET code...
Can static procedures access instance data?
The C#.NET code snippet given below generates ____ numbers series as...
Which of the following statements are correct about the Collection...
Which of the following statements is correct about the C#.NET code...
Which of the following is the correct output of the C#.NET code...
Which of the following is the correct output for the C#.NET program...
Which of the following statements are correct about a .NET Assembly? ...
Which of the following is the correct way to rewrite the following...
For the code snippet given below, which of the following statements is...
Once applied which of the following CANNOT inspect the applied...
Which of the following is the correct way to apply an attribute to an...
What will be the output of the C#.NET code snippet given below? ...
For the code snippet shown below, which of the following statements...
 ...
Which of the following statements is correct about classes and objects...
Which of the following statements is correct about the C#.NET program...
Alert!

Advertisement