1)What is .NET framework?
Explain its architecture
Ans: .NET Framework is a platform created by Microsoft for building, deploying, and running
applications and services that use .NET technologies, such as desktop applications and Web services.
It is a platform for application developers.
It is a Framework that supports Multiple Language and Cross language integration.
It has IDE (Integrated Development Environment).
Framework is a set of utilities or can say building blocks of our application system.
.NET Framework provides interoperability between languages i.e. Common Type System (CTS).
.NET Framework also includes the .NET Common Language Runtime (CLR), which responsible
for maintaining the execution of all applications developed using the .NET library.
The .NET Framework consists primarily of a gigantic library of code.
Components of the .Net Framework:
User Interface and Program:
We can create various type of application using .net framework such as
Console Application
Windows Application
Web application
Base class Library:Base class library is one of component of .Net Framework. It supplies a library of base
classes that we can use to implement applications quickly.
CLR (Common Language Runtime): Common Language Runtime (CLR) is the programming (Virtual
Machine component) that manages the execution of programs written in any language that uses
the .NET Framework, for example C#, VB.Net, F# and so on. We can say that it is heart and soul of .Net
Framework or backbone.
CTS (Common Type System): It specifies a standard that represent what type of
data and value can be defined and managed in computer memory at runtime.
CLS (Common language Specification): It is a subset of common type system
(CTS) that defines a set of rules and regulations which should be followed by every
language that comes under the .net framework.
Microsoft .NET Assemblies:A .NET assembly is the main building block of
the .NET Framework. It is a small unit of code that contains a logical compiled code
in the Common Language infrastructure (CLI), which is used for deployment,
security and versioning.
FCL (Framework Class Library): It provides the various system functionality in
the .NET Framework, that includes classes, interfaces and data types, etc. to create
multiple functions and different types of application such as desktop, web, mobile
application, etc.
2) Q2. Explain CLR in detail.
Ans: Common Language Runtime (CLR) is the programming (Virtual Machine component) that
manages the execution of programs written in any language that uses the .NET Framework, for
example C#, VB.Net, F# and so on.
We can say that it is heart and soul of .Net Framework or backbone.
Programmers write code in any language, including VB.Net, C# and F# then they compile their
programs into an intermediate form of code called CLI in a portable execution file (PE) that can
be managed and used by the CLR and then the CLR converts it into machine code to be will
executed by the processor.
The information about the environment, programming language, its version and what class
libraries will be used for this code are stored in the form of metadata with the compiler that tells
the CLR how to handle this code.
The CLR allows an instance of a class written in one language to call a method of the class
written in another language.
Components of the CLR:
CTS: Common Type System (CTS) describes a set of types that can be used in different .Net languages in
common. That is, the Common Type System (CTS) ensure that objects written in different .Net languages
can interact with each other. For Communicating between programs written in any .NET complaint
language, the types must be compatible on the basic level. These types can be Value Types or Reference
Types. The Value Types are passed by values and stored in the stack. The Reference Types are passed by
references and stored in the heap.
CLS: CLS stands for Common Language Specification and it is a subset of CTS. It defines a set of rules and
restrictions that every language must follow which runs under .NET framework. The languages which
follow these set of rules are said to be CLS Compliant. In simple words, CLS enables cross-language
integration or Interoperability.
MSIL: It is language independent code. When you compile code that uses the .NET Framework library,
we don't immediately create operating system - specific native code. Instead, we compile our code into
Microsoft Intermediate Language (MSIL) code. The MSIL code is not specific to any operating system or
to any language.
Advantages -
MSIL provide language interoperability as code in any .net language is compiled on MSIL
Same performance in all .net languages
support for different runtime environments
JIT compiler in CLR converts MSIL code into native machine code which is executed by OS
Functions of the CLR
Garbage Collector
Exception handling
Type safety
Memory management (using the Garbage Collector)
Security
Improved performance
3)Control flow statement from book
4)Difference between for each and for loop
Ans:
Best suited for iterating over a range or collection Specifically designed for iterating through
Usage with a known number of iterations. collections and arrays.
for (initialization; condition; foreach (type variable in
Syntax iteration) collection)
Requires manual initialization of a loop control Automatically assigns each element in the
Initialization variable. collection to the specified variable.
Provides fine-grained control over loop Automatically iterates through each
Control initialization, condition, and iteration. element in the collection.
Collection Can be used with any class that implements Requires a collection that implements
Type IEnumerable or has a defined indexer. IEnumerable or an array.
You can manually modify the loop control variable You cannot directly modify the elements
Modifying inside the loop body. of the collection being iterated.
Generally faster for indexed collections or May have slightly more overhead due to
Performance iterating over a specific range. its automatic nature.
Useful for scenarios where you need to control Preferred when you want to iterate
Use Cases the loop precisely. through all elements in a collection.
5)arrays
6)methods
7) Explain method overriding with example
Ans:
Method overriding in C# is achieved through inheritance.
If a class is inherited by a derived class, then the derived class can override the base class
method. This concept is termed as Method Overriding.
Method Overriding is implemented in C# using the keywords virtual and override. The base class
method that has to be overridden must be marked as virtual or abstract (if the base class is an
abstract class).
The derived class method that overrides the base class method should be marked with the
keyword override.
using System;
class A
public virtual void Test() { Console.WriteLine("A::Test()"); }
class B : A
public override void Test() { Console.WriteLine("B::Test()"); }
class C : B
public override void Test() { Console.WriteLine("C::Test()"); }
class Program
static void Main(string[] args)
A a = new A();
B b = new B();
C c = new C();
a.Test(); // output --> "A::Test()"
b.Test(); // output --> "B::Test()"
c.Test(); // output --> "C::Test()"
a = new B();
a.Test(); // output --> "B::Test()"
b = new C();
b.Test(); // output --> "C::Test()"
Console.ReadKey();
8) Is Multiple Main () allowed in C#? Justify
Ans: We can use more than one Main Method in C# program, But there will only one Main Method
which will act as entry point for the program.
using System;
class A
static void Main(string[] args)
Console.WriteLine("I am from Class A");
Console.ReadLine();
class B
{
static void Main(string[] args)
Console.WriteLine("I am from Class B");
Console.ReadLine();
In this code, there are two Main() methods defined. If you try to compile this program, you will receive
an error message indicating that there are conflicting entry points.
To resolve this issue, you need to remove or comment out one of the Main() methods, leaving
only one as the entry point for your program.
Method/function overloading
Ans: Method Overloading is the common way of implementing polymorphism. Function
overloading is a feature in many programming languages, including C#, that allows
you to define multiple functions with the same name but with different parameter
lists. This means that you can have multiple versions of a function that perform
similar operations but take different types or numbers of arguments