*2 mark questions.
•1) Foreground Thread:-i) These threads are created using the thread class in C# and are
considered to be the main threads of an [Link]) A foreground thread prevents the
application from terminating until all foreground threads have completed their tasks.
iii) A foreground thread can be created by calling the [Link]() method.
•2) Background Thread:-i) These threads are also created using the thread class in C#, but
they are considered to be the secondary threads of an [Link]) They do not prevent the
application from terminating, even if they are still running.
•3) Thread:-Every program that executes on your system is a process and to run the code
inside the application a process uses a term known as thread.
•4) Enum:-i) Enumeration (enum) is a value data type in C#.ii) It is mainly used to assign the
names or strings values to integral constants that make a program easy to read and
[Link]) Enumeration is declared using the enum keyword directly inside a namespace,
class or structure.
•5) Tuples:-i) The word Tuple means "a data structure which consists of multiple parts".
ii) So, tuple is a data structure which gives you the easiest way to represent a dataset which
has multiple values that may / may not be related to each other.
•6) Method overloading:-i) Method overloading is the common way of implementing
[Link]) It is the ability to redefine a function in more than one form.
iii) A user can implement function overloading by defining two or more functions in a class
sharing the same name.
•7) Method overriding:-i) Method overriding in C# is similar to the virtual function in C++.
ii) Method overriding is a technique that allows the invoking of functions from another class
in the derived class.
•8) Garbage Collection:-i) Garbage Collection is a memory management technique used in
the .NET framework and many other programming [Link]) In C#, the garbage collector
is responsible for managing memory and automatically freeing up memory that is no longer
being used by the application.
•9) IDisposable:-i) The primary use of the IDisposable interface is to release unmanaged
[Link]) The garbage collector automatically releases the memory allocated to a
managed object when the object is no longer used.
•10) Abstract Class:-i)An abstract class is an incomplete class or special class that can't be
instantiated. ii)The purpose of an abstract class is to provide a blueprint for derived classes
and set some rules on what the derived classes must implement when they inherit an
abstract class.
•11) Delegate:-i) CTS supports delegates which are type-safe function [Link]) Delegates
enable the creation of callback functions and event handling.
•12) Exceptions:-i) Exceptions are unexpected events that may arise during runtime.
ii) Exceptions can be handled using try-catch [Link]) All exceptions are not errors.
•13) Indexer:-i) Indexers in C# are data members that act as an array and allow you to
access data within objects to be indexed in the same [Link]) Indexers are always declared as
instance members.
•14) Event:-C# supports events which are used for implementing event handling & callback
mechanisms.
*Q).What is class & object in C#.
=>•Class:-i) A class is a user-defined blueprint or prototype from which objects are created.
ii) A class is like a blueprint of a specific object that has certain attributes & features.
iii) In C# classes support polymorphism & inheritance & also provide the concept of derived
classes & base classes.
•Object:-i) An object is a fundamental data type that represents a real-world entity.
ii) It combines variables \& functions that operate on the data, encapsulating behaviour &
[Link]) objects are instances of classes, defining their structure \& behaviour.
*Q).Features of C#:-
=>•1)Simple:- C# is a user-friendly language that offers a structured approach to problem
solving.
•2)Object oriented:- C# is an object oriented programming language, which makes
development \& maintenance easier.
•3)Type safe:- The code is type safe and can only access memory locations that it has
permission to exclude. This feature enhances program security.
•4)Fast speed:- The compilation \& execution time of C# His language is fast.
•5)Structured Programming language:- C# is structured. programming language that allows
us to divide programs into parts using functions.
***Fill in the blanks:-
•1)Class data members in C# are Private by default.
•2).NET Libraries are intended to be common libraries that any other application can use.
•3)To handle situations where multiple threads access shared data, you can use a Locking
mechanism to synchronize access.
•4) ref parameters are used to pass the result back to the calling method and it does not
create a new storage location.
•5)The class used to create a new thread in C# is called Thread.
•6)Virtual method defined in Base class is inherited by it's derived class.
***Fill in the blanks:-
•1)The IEnumerable<T> interface is the base interface for all generic collections in C#.
•2)Destructors are called automatically by the garbage collector during garbage collection.
•3)The exception that occurs when a requested file cannot be found is known as
FileNotFoundException.
•4)All classes in C# are reference types, which means they are stored on the Heap.
•5)To create a reference to an instance of a class, you use the new keyword followed by the
class name.
•6)The ReadLine() method can be used to read a single character from the console.
*Q). What is multithreading in C# & explain thread life cycle.
=>•Multithreading: C# is a multi-paradigm programming language that supports several
programming styles, including procedural, object-oriented & functional programming. One of
the essential features of C# is its support for multithreading which enables developers to
write applications that can perform multiple tasks concurrently.
•Explain Thread life cycle:-
~The thread life cycle represents the different states a thread goes through from creation to
termination in a program.
[Create state(new)]> [Runnable] >[Running] >[Waiting]> [Timed Waiting] >[Terminated]
•1) Create State (New):-A thread object is created using [Link](), but the thread
has not yet started running.
•2) Runnable (Ready state):-When you call [Link]() (where 't' is the thread object), the thread
is moved to the runnable pool.
It is ready to run but not running immediately. The Operating System (O.S.) scheduler and
the GIL (Global Interpreter Lock) in Python decide when it will run.
•3) Running (Active state):-The thread gets CPU time and begins to execute the target
function (the code inside its run() method).
•4) Waiting (Blocked state):-A thread moves to this state if it's waiting for an I/O operation
(like reading from a file or network), waiting to acquire a lock (mutex, semaphore), or
performing an explicit wait, etc.
The thread is inactive and cannot be run until the blocking condition is resolved.
•5) Timed Waiting:-The thread waits for a specific period of time before moving back to the
Runnable state.
This state is typically entered when a method like [Link](n) or [Link](timeout) is called.
•6) Terminated:-Once the run() or target function completes execution, the thread enters the
Terminated (Dead) state.
A thread that has terminated cannot be restarted.
*Q). What are delegate & explain single cast & multicast delegate with ex.
=>i) Delegates in C# are objects that represent methods. They allow you to treat method as
values or passing them as a parameter & adding them to collection.
ii) Delegate is a type-safe function pointer if it is declared using the 'delegate' keyword.
iii) Delegate used to pass methods as arguments to other methods.
•Types of Delegate:
•1)Single cast delegate:-
i) A single cast delegate refers to a single method at a [Link]) When you invoke a single-cast
delegate, it executes only the method it currently references.
•2)Multicast delegate:-
These delegates can hold multiple methods. You can use the '+' operator to add methods to
a multicast delegate & the '-' operator to remove method. When you invoke a multicast
delegate, it executes all the methods in its invocation list.
* Difference between Constructor and Destructor.
Constructor Destructor
Constructor are used when instantiating a Destructor are used to clean up resources
class. used by the object.
Constructor can have access modifiers. Destructor can't have access modifiers.
Constructor can have parameter(s). Destructor can't have parameter(s).
Constructor can be multiple in a class. Destructor can't be multiple in a class. A
Destructor unique to its class.
Constructor can be define in structure. Destructor can't be define in structure.
*Difference between .NET Framework & .NET Core.
Category .NET Framework .NET Core
History The .NET Framework is the .NET Core is the latest
first implementation of .NET. implementation of .NET.
Open Source Certain components of the .NET Core is open source.
.NET Framework are open
source.
Cross Platform It works only on the windows It runs cross platform like
platform. It does not support window, linux & macos.
cross platform deployment.
Third-Party Package Support There are many third party The .NET Core also support
packages, libraries available. large No. of third party
packages.
In-app Deployment It doesn't support the in-app It support the In-app
deployment model. deployment model.
Command Line Tools .NET Framework is heavy for .NET Core provides
command line interface. lightweight editors &
command line tools for all
supported platforms.
* Difference Between Structure and Class.
Structure Class
It is value Type. It is a reference type.
All the value Types are allocated on stack All reference type are allocated on the heap
memory. memory.
Structure has limited feature. Classes has limitless Features.
Structure does not contain parameter less Class can contain constructor or Destructor.
constructor or Destructor.
Structure is not allowed to inherit from A class can inherit from another class.
another struct or class.
It is Declared using struct. It is Declared using class.
*Q.)Explain Access modifiers in C#.
=>i) Access modifiers in C# are keyword that control the accessibility level of types (like
classes, structures, interfaces) & type members (like fields, methods, properties) etc.
ii) They determine where and how these elements can be accessed within a program,
playing a crucial role in encapsulation & object oriented design.
•1)public:-Access is not restricted. Members declared as public can be accessed from any
code, in the same assembly, or
~Example:public class Myclass
{ public int public field;
public void public method () {} }
•2)private:- Access is limited to the containing type. Members declared as private can only
be accessed from within the same class or structure where they are defined.
~Example:public class Myclass
{ private int private field;
private void Private Method () {} /* ... */ }
•3)protected:-Access is limited to the containing type & any type derived from it. members
declared as protected can be accessed within the same class & any class that inherits from
it.
*Q). What is Serialization & Explain JSON Serialization & XML Serialization.
=>•Serialization:-i) Serialization is the process of converting an object's state (it's data &
properties) into a format that can be stored or [Link]) This allows the object to save a
file, sent across a network, or exchange between different applications or systems.
•JSON Serialization:-JSON (JavaScript Object Notation) serialization converts .NET objects
into a lightweight, human readable text format based on key-value pair.
Namespace used: [Link]
•XML Serialization:-XML (eXtensible Markup Language) serialization converts .NET objects
into structured XML documents that can be shared across systems.
Namespace used: [Link]
*Q). Exception Handling.
=>i) Exception handling in .NET core provides a mechanism to manage & respond to
runtime error or unexpected events, preventing application & ensuring a more robust & user
friendly [Link]) In exception handling such keywords are used such as:
* try: Contain the code that may throw an exception. * catch: Used to handle (catch) the
exception. * finally: Execute code whether or not an exception occurs.
*Q).Explain Boxing & Unboxing with ex:-
=>•Boxing:-i) The process of converting a Value Type variable to a Reference Type variable
is called [Link]) Boxing is an implicit conversion process in which object type is [Link])
Value Type variables are always stored in Stack memory, while Reference Type variables
are stored in Heap memory.
~ex:-int num = 23; $\quad$ // 23 will assigned to num. object obj = num; // Boxing.
•Unboxing:-i) The process of converting a Reference Type variable into a Value Type
variable is known as [Link]) It is an explicit conversion process.
ex:-int num = 23;
object obj = num; // Boxing.
int i = (int) obj; // Unboxing.
*Q).What is .NET:-
=>i) .NET is a software development platform from Microsoft.
ii) It's Free, open-source, & cross-platform, supporting various operating systems like
Windows, Linux & macOS.
iii) .NET supports multiple programming languages with C# being the most popular
according to Teno va. Tenova.
iv) Programmers can build different applications using .NET, including web, mobile, desktop,
gaming & 10 T apps.
*Q).Components of .NET Framework:
=>•1)CLR (Common Language Runtime):-
i) The CLR is the heart of the .NET Framework, acting as a virtual machine that runs the
code & manages various services such as memory management, security, & thread
management.
ii)Code that is compiled & executed within the CLR is called managed code, while code that
the CLR does not manage is known as unmanaged code.
•2)FCL (.NET Framework Class Library):-
i) The FCL provides a large set of reusable classes & methods for application development.
ii) It provides built-in support for file handling, Database operations, networking etc.
•3)BCL (Base Class Library):-
The **Base Class Library (BCL) is a core set of pre-built classes & types that provides the
fundamental functionality for all applications developed on the .NET platform.
*Q).Data types in C#.
=>Data types in C# is mainly divided into two categories.
* Value Data Type.
* Reference Data type.
•1)Value Data Type:-
i) Value Data Type stores the actual data directly in the memory location & it will also accept
the both signed & unsigned literals.
ii) Value data types in C# programming language.
~a)Signed & unsigned integral Type:-
There are 8 integral type which provide support for 8-bit, 16-bit, 32 bit & 64-bit value in
signed or unsigned form.
~b)Floating Point Type:- There are 2 floating point data type.
*Float: It is a 32-bit single precision floating point type. It has 7 digit precision. To initialize a
float variable, use the suffix f or F.
*Double: It is a 64-bit double precision floating point type. It has 14-15 digit precision. To
initialize a double variable, use the suffix d orD.
•2)Reference Data Types:-
i)Reference Data type will contain a memory address of variable value because the
reference type does not store variable value directly in memory.
* Two types of reference data type:-
* string, * object
*a) String: - It represents a sequence of unicode characters & its type name is
[Link]. So, string & String are equivalent.
* b)Object: - It is the base class for all the data types in C#. Before assigning value. It's type
name is [Link]:
*Q). Discuss inheritance in C#. Explain different types of Inheritance.
=> i) In C#Inheritance is a process in which one object acquires all the properties of its
parent object automatically.
ii) Acquiring the properties of one class into another is called inheritance.
iii) In C#, the class which inherits the member of another class is called derived class & the
class whose members are inherited is called Base class.
•Types of Inheritance:-
single, hierarchical, Multilevel.
•1)Single Inheritance:- It is the type of inheritance in which there is one base class & one
derived class.
~Diagram:-
[ Class A (Base class) ]
{
}
[ Class B : A (derived class) ]
{
}
•2)Hierarchical Inheritance :-This is the type of Inheritance in which there are multiple
classes derived from one base class.
~Diagram:-
[ Class A (Base class) ]
{
}
[ Class B : A ]
{
}
[ Class C : A ]
{
}
[ Class D : A ]
{
}
•3)Multilevel Inheritance:-When one class is derived from another, this type of inheritance is
called multilevel inheritance.
[ Class A ]
{
}
[ Class B : A ]
{
}
[ Class C : B ]
{
}
*Q). Explain the .NET architecture with its components.
=>
•1).NET Framework:-
i) It is used for developing windows-based applications. It includes application models like
Windows Forms, WPF (Windows Presentation Foundation), Console & [Link].
•2) .NET Core:- .NET Core is an open-source, cross platform Framework for building
applications & microservices, including Console & [Link] Core.
•3)Xamarin:- It is a Framework for creating cross-platform mobile applications for iOS, Mac
OS, & Android.
•4) .NET Standard library:-
This layer allows developers to create code that can be shared across different platforms like
.NET Framework, .NET core & Xamarin.
•5)Common Infrastructure:-
This layer includes the core components that are shared across different .NET
implementations. It consist of:
~a)Compiler:-It translates the source code of a program into an intermediate language (IL).
~b)Languages:-The programming languages supported by .NET, such as C#, F# & Visual
Basic.
~c)Runtime components:-Runtime components responsible for executing the compile code.
*Q)Explain the architecture of LINQ.
=>
-LINQ is known as Language Integrated Query & it is introduced in .NET 3.5 & Visual Studio
2008.
-The beauty of LINQ is it provide the ability to .NET languages (like C#, [Link]) to generate
query to retrieve data from data source.
-The architecture of LINQ is a 3 layer architecture.
* Language layer
* LINQ provider layer
* Data source layer
•1)Language layer:-
i) This layer provides query syntax that is integrated directly into .NET languages like C# &
[Link] by using query syntax & lambda expression.
•2)LINQ provider layer:
This layer Translates queries into the Format understood by different data sources (e.g.,
SQL, XML, or objects). Ex: LINQ to object, LINQ to SQL, LINQ to XML. etc.
•3)Data source layer:-
It is the actual data that LINQ queries work on such as collections, databases, or XML
Documents.
*[Link] a program for multicast delegate.
=>using System;
namespace MulticastDelegateExample
{
public delegate void NotifyDelegate();
class Program
{
static void SendEmail()
{
[Link]("Email sent successfully.");
}
static void SendSMS()
{
[Link]("SMS sent successfully.");
}
static void SendPushNotification()
{
[Link]("Push notification sent successfully.");
}
static void Main(string[] args)
{
NotifyDelegate notify1 = SendEmail;
NotifyDelegate notify2 = SendSMS;
NotifyDelegate notify3 = SendPushNotification;
NotifyDelegate multicastNotify = notify1 + notify2 + notify3;
[Link]("Invoking Multicast Delegate:\n");
multicastNotify();
multicastNotify -= notify2;
[Link]("\nAfter removing SMS delegate:\n");
multicastNotify();
}
}
}
•Output:
Invoking Multicast Delegate:
Email sent successfully.
SMS sent successfully.
Push notification sent successfully.
After removing SMS delegate:
Email sent successfully.
Push notification sent successfully.
*Q).Write a program for method overloading in .net core.
=>using System;
namespace MethodOverloadingExample
{
class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
public int Add(int a, int b, int c)
{
return a + b + c;
}
public double Add(double a, double b)
{
return a + b;
}
public string Add(string message, int number)
{
return message + [Link]();
}
}
class Program
{
static void Main(string[] args)
{
Calculator calc = new Calculator();
[Link]("Addition of two integers: " + [Link](10, 20));
[Link]("Addition of three integers: " + [Link](10, 20, 30));
[Link]("Addition of two doubles: " + [Link](5.5, 4.3));
[Link]("Addition of string and integer: " + [Link]("Result is: ", 100));
}
}
}
•Output:-
Addition of two integers: 30
Addition of three integers: 60
Addition of two doubles: 9.8
Addition of string and integer: Result is: 100
*Q).Write a program which implement function overriding.
=>using System;
namespace FunctionOverridingDemo
{ class Animal
{ public virtual void Speak()
{ [Link]("Animal makes a sound");
}
} class Dog : Animal
{ public override void Speak()
{ [Link]("Dog barks");
}
} class Cat : Animal
{ public override void Speak()
{ [Link]("Cat meows");
}
} class Program
{ static void Main(string[] args)
{ Animal a1 = new Animal();
[Link]();
Animal a2 = new Dog();
[Link]();
Animal a3 = new Cat();
[Link]();
[Link](); } }}
*Q)Write a program which can implement multiple interfaces.
=> using System;
namespace MultipleInterfaceDemo
{ interface IReadable
{ void Read() }
interface IWritable
{ void Write(); }
class Document : IReadable, IWritable
{
public void Read()
{ [Link]("Reading the document...");
} public void Write()
{ [Link]("Writing to the document..."); } }
class Program
{ static void Main(string[] args)
{ Document doc = new Document();
[Link]();
[Link]();
IReadable readable = doc;
[Link]();
IWritable writable = doc;
[Link]();
[Link](); } } }