C#prog
C#prog
class Program
{
private static string result;
Hello user!
Q2 of 25
Consider the following code snippet:
Option b (correct)
Option c
Option d
Q3 of 25
What will be the output for the below given code snippet:
SortedList sortList= new SortedList();
sortList.Add(10, null);
sortList.Add(null, "Chennai");
sortList.Add(30, "Chennai");
sortList.Add(20, "Bangalore");
Q4 of 25
What will be the output of the following code snippet?
Console.WriteLine(at1.GetType() == at2.GetType());
Console.WriteLine(at1 == at2);
Console.WriteLine(at1.Equals(at2));
}
Choose the correct option:
a. True
True
True
b. True
False
False
c. True
False
True
d. False
True
False
Option a
Option b
Option c (correct)
Option d
Q5 of 25
Consider the following code snippet:
Q6 of 25
Consider the following code snippet:
Q7 of 25
Anonymous methods allow code blocks to be written ___________.
Q8 of 25
Predict the output of the below code snippet:
Console.WriteLine(resultDel(12,10));
}
static int Addition(int num1, int num2)
{
return (num1 + num2);
}
static int Subtraction(int num1, int num2)
{
return (num1 - num2);
}
static int Multiplication(int num1, int num2)
{
return (num1 * num2);
}
}
140
144
120 (correct)
142
Q9 of 25
Consider the following code snippet:
Option a
Option b
Option c (correct)
Option d
Q10 of 25
Consider the following code snippet:
// LINE 01 - code to open the file "Log.txt" and read the contents from
it
Q11 of 25
Which of the following statements about Generics is FALSE?
(a) Use generic types to maximize type safety, and improve performance
(b) Generics has introduced the concept of type parameters in .NET Framework
Only (a)
Only (b)
Q12 of 25
While creating the List<TEntity> instance, the Capacity property is set to 3. What
will be the capacity when 4th element is added to the collection?
6 (correct)
Q13 of 25
When designing a class, it is recommended to avoid using the Finalize() method.
Q14 of 25
Consider the following code snippet:
var result = isdCodes.Where(c => c.Value > 50 && c.Key.Length == 5); (correct)
var result = isdCodes.Where(c => c.Value > 50 || c.Key.Length == 5);
Q15 of 25
Identify which of the built-in delegate is used in the following Lambda Expression
(the code underlined below).
Func<>
Action<>
Predicate<> (correct)
MulticastDelegate
Q16 of 25
What is the output of the following code?
class Program
{
static void Main(string[] args)
{
SortedList myList = new SortedList();
myList.Add('m', "Harry");
myList.Add('a', "Mark");
myList.Add('b', "Scott");
myList.Add('h', "John");
myList.Add('d', "Larry");
myList.GetByIndex(1);
Console.WriteLine(myList.GetByIndex(1));
}
}
Mark
Larry
Harry (correct)
Scott
Q17 of 25
Identify the invalid statements among the following:
var z = null;
var v = 3;
var x = x++; (correct)(wrong)
Q18 of 25
What will be output for the below code snippet?
}
}
}
Choose the following option:
a. Dispose()
Dispose()
b. Dispose()
Option a (correct)
Option b
Option c
Option d
Q19 of 25
Consider the following code snippet:
In the context of delegates, the signature of a delegate does not include the
return value. Hence in the code snippet, return type 'int' should be replaced with
return type 'void'
Compile Time Error: The Type Program already contains a definition for Calc. This
error is due to statement 'public delegate int Calc(double x, int y)' (correct)
Q20 of 25
Consider the following code snippet:
Q21 of 25
Consider the following code snippet:
Option a (correct)
Option b
Option c
Option d
Q22 of 25
Which among the following option holds good for Extension Methods in C#?
The return type of the extension method will be the type that is extended
The first parameter of the extension method uses 'base' modifier followed by the
type that is being extended
Extension methods are helpful in scenarios where the class is sealed and yet one
wants to extend its functionality, without the concept of inheritance (correct)
Q23 of 25
Which of the following statement(s) about built-in generic delegates are TRUE?
(a) Func delegate can take parameters and must return any value
(b) Action delegate doesn't take parameters and doesn't return a value
(c) Predicate delegate can take parameters but returns only int value
Only (c)
Q24 of 25
Arrange the below in the order of Garbage collection while reclaiming the memory.
(i) The garbage collector frees objects that are not referenced and reclaims
their memory
(ii) The garbage collector searches for managed objects that are referenced in
managed code
(iii) The garbage collector tries to finalize objects that are not referenced
ii, i, iii
i, iii, ii
iii, ii, i
Q25 of 25
What will be the output of the following code snippet?
class Demo
{
static void Main(string[] args)
{
int value1 = 10;
int value2 = 20;
int[] myArray = { 1, 2, 0 };
try
{
double result = value1 / myArray[4];
try
{
double result2 = value2 / myArray[2];
}
catch (Exception e1)
{
Console.Write("one ");
}
finally
{
Console.Write("finally ");
}
}
catch (IndexOutOfRangeException e2)
{
Console.Write("two ");
}
catch (DivideByZeroException e3)
{
Console.Write("three ");
}
}
}
Choose from the following option:
a. two
finally
b. one
finally
c. Compile Time Error - The generic exception cannot appear before the specific
exception
d. finally
two
e. two
Option a
Option b (correct)
Option c
Option d
Option e