0% found this document useful (0 votes)
11 views

CSharp_Exam_Questions_and_Solutions

The document contains C#.NET exam questions and solutions covering various topics such as advantages of C#, benefits of the .NET framework, MSIL, control statements, method overloading, destructors, data types, .NET architecture, and the difference between classes and interfaces. It includes code examples for practical understanding. The content is structured in a question-answer format, making it suitable for exam preparation.

Uploaded by

inaglepankaj2213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

CSharp_Exam_Questions_and_Solutions

The document contains C#.NET exam questions and solutions covering various topics such as advantages of C#, benefits of the .NET framework, MSIL, control statements, method overloading, destructors, data types, .NET architecture, and the difference between classes and interfaces. It includes code examples for practical understanding. The content is structured in a question-answer format, making it suitable for exam preparation.

Uploaded by

inaglepankaj2213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

C#.

NET-I Exam Questions and Solutions

1A. Attempt any two

a) Explain the advantages of using C# over other programming languages.

C# offers several advantages over other programming languages:

1. **Object-Oriented Programming (OOP)** - Supports encapsulation, inheritance, and


polymorphism.
2. **Garbage Collection** - Automatic memory management reduces memory leaks.
3. **Cross-Platform Development** - With .NET Core, C# applications can run on Windows,
Linux, and macOS.
4. **Rich Library Support** - The .NET Framework provides extensive pre-built libraries.
5. **Security** - Strong type-checking and access modifiers enhance security.
6. **Integration with .NET** - Works seamlessly with ASP.NET, ADO.NET, and other .NET
technologies.

b) Explain the benefits of using the .NET framework for software development.

The .NET framework provides several benefits:

1. **Language Interoperability** - Allows multiple programming languages to work


together.
2. **Common Language Runtime (CLR)** - Manages code execution and memory
management.
3. **Security Features** - Provides code access security and role-based security.
4. **Scalability** - Suitable for building small to large-scale applications.
5. **Rapid Development** - Pre-built libraries and tools speed up software development.

c) What is MSIL? Explain its role in .NET.

Microsoft Intermediate Language (MSIL) is the low-level language into which .NET
languages are compiled before execution.

1. **MSIL is platform-independent**, allowing execution on different operating systems.


2. The **Common Language Runtime (CLR)** converts MSIL to native code using Just-In-
Time (JIT) compilation.
3. **Enhances security and performance** by optimizing execution.
2A. Attempt any two

a) Explain the use of break and continue statements in C#.

The `break` and `continue` statements are used for controlling loops.

1. **break statement:** Exits the loop immediately.


2. **continue statement:** Skips the current iteration and proceeds to the next.

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).

b) Write a do-while loop in C#.

A `do-while` loop executes at least once before checking the condition.

Example:
```csharp
int num = 1;
do {
Console.WriteLine(num);
num++;
} while (num <= 5);
```
This will print numbers 1 to 5.

3A. Attempt any two

a) What is method overloading in C#?

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.

b) What is the purpose of a destructor in C#?

A destructor (`~ClassName()`) is used to clean up resources when an object is destroyed.

Example:
```csharp
class Sample {
~Sample() { Console.WriteLine("Destructor called"); }
}
```
Destructors are useful for releasing unmanaged resources like file handles.

c) Explain the different data types in C#.

C# supports several data types:

1. **int** - Stores integers (e.g., `int x = 10;`).


2. **float** - Stores decimal numbers with lower precision.
3. **double** - Stores decimal numbers with higher precision.
4. **char** - Stores single characters (`char c = 'A';`).
5. **string** - Stores sequences of characters (`string name = "John";`).
6. **bool** - Stores true/false values (`bool isReady = true;`).

4A. Attempt any two

a) Describe the architecture of the .NET framework and its components.

The .NET framework consists of:

1. **Common Language Runtime (CLR)** - Manages execution.


2. **Framework Class Library (FCL)** - Provides built-in functions.
3. **Common Type System (CTS)** - Ensures language interoperability.
4. **Just-In-Time (JIT) Compiler** - Converts MSIL to machine code.
b) Explain the difference between a class and an interface in C#.

| Feature | Class | Interface |


|----------|-------|-----------|
| Definition | A blueprint for creating objects. | A contract that defines a set of methods
without implementation. |
| Implementation | Can have method definitions and implementations. | Only contains
method signatures, no implementation. |
| Inheritance | Supports single inheritance. | Supports multiple inheritance. |
| Members | Can have fields, methods, constructors, and properties. | Only method
declarations, no fields or constructors. |

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"); }
}
```

c) Write a program in C# to check whether a number is a palindrome.

A palindrome number remains the same when reversed.

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.

You might also like