C# Programming - Exception Handling - Discussion
Discussion Forum : Exception Handling - General Questions (Q.No. 17)
17.
Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?
using System;
namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main(string[] args)
{
int index;
int vat = 88;
int[] a = new int(5];
try
{
Console.Write("Enter a number: ");
index = Convert.Toint32(Console.ReadLine());
a[index] = val;
}
catch(Exception e)
{
Console.Write("Exception occurred");
}
Console.Write("Remaining program");
}
}
}
Discussion:
3 comments Page 1 of 1.
Shraddha said:
1 decade ago
The answer should be Remaining program. Because exception is not there in the codes. ABCD is a character and converted into integer, so program will run correctly without any error or exception.
Tyrone Atkins said:
9 years ago
Line 9, an error in the code for val. 'vat' is shown as opposed to val.
Kevin said:
7 years ago
@All.
The Code should read: ( int val = 88 not "int vat = 88" and int[] a = new int[5] not "int[] a = new int(5];").
static void Main(string[] args)
{
int index;
int val = 88;
int[] a = new int[5];
try
{
Console.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch (Exception e)
{
Console.Write("Exception occurred");
}
Console.Write("Remaining program");
}
The Code should read: ( int val = 88 not "int vat = 88" and int[] a = new int[5] not "int[] a = new int(5];").
static void Main(string[] args)
{
int index;
int val = 88;
int[] a = new int[5];
try
{
Console.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch (Exception e)
{
Console.Write("Exception occurred");
}
Console.Write("Remaining program");
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers