CSharp_Exam_Questions_and_Solutions
CSharp_Exam_Questions_and_Solutions
b) Explain the benefits of using the .NET framework for software development.
Microsoft Intermediate Language (MSIL) is the low-level language into which .NET
languages are compiled before execution.
The `break` and `continue` statements are used for controlling loops.
Example:
```csharp
for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
Console.WriteLine(i);
}
```
This will print 1, 2, 4, 5 (skipping 3).
Example:
```csharp
int num = 1;
do {
Console.WriteLine(num);
num++;
} while (num <= 5);
```
This will print numbers 1 to 5.
Method overloading allows multiple methods with the same name but different parameters.
Example:
```csharp
class Example {
public void Print(int x) { Console.WriteLine(x); }
public void Print(string x) { Console.WriteLine(x); }
}
```
The compiler determines which method to call based on arguments.
Example:
```csharp
class Sample {
~Sample() { Console.WriteLine("Destructor called"); }
}
```
Destructors are useful for releasing unmanaged resources like file handles.
Example:
Class:
```csharp
class Car {
public void Drive() { Console.WriteLine("Driving a car"); }
}
```
Interface:
```csharp
interface IVehicle {
void Start();
}
class Bike : IVehicle {
public void Start() { Console.WriteLine("Bike started"); }
}
```
Example:
```csharp
int num = 121, rev = 0, temp = num;
while (temp > 0) {
rev = (rev * 10) + (temp % 10);
temp /= 10;
}
if (num == rev) Console.WriteLine("Palindrome");
else Console.WriteLine("Not a Palindrome");
```
This checks if a number is a palindrome.