61. What will be the output of the following C# code?
{
try
{
int []a = {1, 2, 3, 4, 5};
for (int i = 0; i < 7; ++i)
Console.WriteLine(a[i]);
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("0");
}
Console.ReadLine();
}
{
try
{
int []a = {1, 2, 3, 4, 5};
for (int i = 0; i < 7; ++i)
Console.WriteLine(a[i]);
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("0");
}
Console.ReadLine();
}
62. Select the modifiers which can be used with the properties?
63. Which of the following is the wrong statement about exception handling in C#.NET?
64. Which of these keywords are used for the block to handle the exceptions generated by try block?
65. What will be the output of the following C# code?
class student
{
int []scores = new int[5] {23, 42, 54, 11, 65};
public int this[int index]
{
get
{
if (index < 5)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
set
{
if (index < 5)
scores[index] = value;
else
Console.WriteLine("invalid index");
}
}
}
class Program
{
public static void Main(string[] args)
{
student s = new student();
Console.WriteLine(s[4] + 8);
Console.ReadLine();
}
}
class student
{
int []scores = new int[5] {23, 42, 54, 11, 65};
public int this[int index]
{
get
{
if (index < 5)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
set
{
if (index < 5)
scores[index] = value;
else
Console.WriteLine("invalid index");
}
}
}
class Program
{
public static void Main(string[] args)
{
student s = new student();
Console.WriteLine(s[4] + 8);
Console.ReadLine();
}
}
66. Select the statements which describe the correct usage of exception handling over conventional error handling approaches?
67. Which of these exceptions will occur if we try to access the index of an array beyond its length?
68. Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail. Which among the following is the correct solution to ensure this functionality?
69. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the code below to work. Which is the correct solution to ensure this functionality?
b.maths = 10;
Console.WriteLine(b.maths);
b.maths = 10;
Console.WriteLine(b.maths);
70. What will be the output of the following C# code?
class program
{
static void main(string[] args)
{
int i = 5;
int v = 40;
int[] p = new int[4];
try
{
p[i] = v;
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Index out of bounds");
}
Console.WriteLine("Remaining program");
}
}
class program
{
static void main(string[] args)
{
int i = 5;
int v = 40;
int[] p = new int[4];
try
{
p[i] = v;
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Index out of bounds");
}
Console.WriteLine("Remaining program");
}
}
Read More Section(Exception Handling in C Sharp)
Each Section contains maximum 100 MCQs question on Exception Handling in C Sharp. To get more questions visit other sections.