1.
What is the best way to store the connection strings?
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.
2.
Which of the following statements are correct about a .NET Assembly?
- It is the smallest deployable unit.
- Each assembly has only one entry point - Main(), WinMain() or DLLMain().
- An assembly can be a Shared assembly or a Private assembly.
- An assembly can contain only code and data.
- An assembly is always in the form of an EXE file.
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.
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();
}
}
}
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.
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;
}
}
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.
5.
Can static procedures access instance data?
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.
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();
}
}
}
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".
7.
Once applied which of the following CANNOT inspect the applied attribute?
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.
8.
Which of the following is the correct way to apply an attribute to an Assembly?
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#.
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;
}
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.
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);
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
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;
}
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.
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;
}
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.
13.
Which of the following statements is correct about classes and objects in C#.NET?
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.
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));
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.
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 ] + " ");
}
}
}
}
}
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.
16.
Which of the following statements are correct about exception handling in C#.NET?
- If an exception occurs then the program terminates abruptly without getting any chance to recover from the exception.
- No matter whether an exception occurs or not, the statements in the finally clause (if present) will get executed.
- A program can contain multiple finally clauses.
- A finally clause is written outside the try block.
- finally clause is used to perform clean up operations like closing the network/database connections.
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.
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 ");
}
}
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."
18.
Which of the following statements are correct about the Collection Classes available in Framework Class Library?
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.
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);
}
}
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.
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);
}
}
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.