What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 10, b = 0;
int result;
Console.Out.WriteLine("This will generate an exception.");
try
{
result = a / b; // generate an exception
}
catch (DivideByZeroException exc)
{
Console.Error.WriteLine(exc.Message);
}
Console.ReadLine();
}
static void Main(string[] args)
{
int a = 10, b = 0;
int result;
Console.Out.WriteLine("This will generate an exception.");
try
{
result = a / b; // generate an exception
}
catch (DivideByZeroException exc)
{
Console.Error.WriteLine(exc.Message);
}
Console.ReadLine();
}A. This will generate an exception
B. 0
C. Compile time error
D. This will generate an exception
Attempted to Divide by Zero
Answer: Option D
Which class in C# is used to read data from text files?
A. TextReader
B. FileReader
C. FileWriter
D. StreamReader
What is the purpose of the using statement when working with files in C#?
A. To read data from files
B. To write data to files
C. To ensure proper disposal of resources
D. To handle exceptions
In C#, which method is used to write data to a text file?
A. Write()
B. WriteLine()
C. WriteText()
D. Append()
What is the correct way to open a file for writing in C#?
A. FileStream file = new FileStream("filename.txt", FileMode.Write);
B. StreamWriter file = new StreamWriter("filename.txt");
C. File.OpenWrite("filename.txt");
D. None of the above

Join The Discussion