0% found this document useful (0 votes)
23 views2 pages

MICRO

The .NET Framework is a software development framework from Microsoft that provides a programming model, class libraries, and runtime for building applications. It includes the Common Language Runtime (CLR) which manages memory, security, and code execution. CLR provides services like garbage collection, exception handling, and memory management. C# is a popular programming language used to build applications on the .NET Framework.

Uploaded by

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

MICRO

The .NET Framework is a software development framework from Microsoft that provides a programming model, class libraries, and runtime for building applications. It includes the Common Language Runtime (CLR) which manages memory, security, and code execution. CLR provides services like garbage collection, exception handling, and memory management. C# is a popular programming language used to build applications on the .NET Framework.

Uploaded by

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

1. What is .net framework . explain the components of 9.

9. Community support: Community support is essential for any framework to C# is a modern, object-oriented programming language developed by 4. What is exception handling ?
framework. ensure that developers can get help and share knowledge with each other. Microsoft as part of the .NET Framework. It is designed to be simple, efficient,
2. what is CLR ? describe the services provided by CLR. and easy to learn, making it a popular choice for developing a wide variety of Exception handling is a mechanism in programming that allows developers to
applications. handle errors and unexpected events that may occur during the execution of a
.NET Framework is a software development framework developed by Microsoft
CLR stands for Common Language Runtime, which is a component of the .NET program. When an error occurs, an exception is thrown, which can be caught
that provides a programming model, a comprehensive set of class libraries, and
Framework that provides a runtime environment for executing managed code. Some of the key features of C# include: and handled by the program.
a runtime environment for developing and executing applications on Windows-
It is responsible for managing memory, enforcing security, handling exceptions, 1. Object-oriented programming: C# supports object-oriented programming
based operating systems.
and providing other services that are required by .NET applications. concepts such as inheritance, polymorphism, and encapsulation. 1. try: This keyword is used to enclose a block of code that may throw an
The components of the .NET Framework : exception. The code inside the try block is executed normally, but if an
1. Common Language Runtime (CLR): It is the runtime environment that The services provided by CLR include: 2. Garbage collection: C# includes automatic memory management through exception is thrown, the program will jump to the catch block.
manages memory, security, and code execution for .NET applications. It also garbage collection, which helps developers avoid common memory-related
provides services such as garbage collection, exception handling, and thread 1. Memory management: CLR manages memory allocation and deallocation errors. 2. catch: This keyword is used to define a block of code that handles an
management. for .NET applications, including garbage collection to automatically free up exception that has been thrown. The catch block specifies the type of exception
memory that is no longer needed. 3. Type safety: C# enforces type safety at compile time, reducing the likelihood it can handle, and if that type of exception is thrown, the code inside the catch
2. Class Library: It is a collection of reusable classes, interfaces, and value types of runtime errors caused by type mismatches. block is executed.
that provide access to system functionality such as file I/O, networking, and 2. Code execution: CLR compiles and executes .NET code, including Just-In-
database connectivity. Time (JIT) compilation to convert intermediate language (IL) code into machine 4. Cross-platform development: C# can be used to develop applications that 3. finally: This keyword is used to define a block of code that is executed
code at runtime. run on Windows, Linux, and macOS. regardless of whether an exception was thrown or not. The finally block is
3. Language Interoperability: It allows developers to use multiple programming always executed, even if there is no catch block or if the catch block does not
languages to write .NET applications, including C#, Visual Basic .NET, F#, and 3. Security: CLR provides a secure execution environment for .NET applications, 5. Asynchronous programming: C# includes support for asynchronous handle the exception.
others. including code access security and role-based security. programming, which allows developers to write code that runs concurrently
without blocking the main thread. 4. throw: This keyword is used to manually throw an exception from within a
4. APIs: Application Programming Interfaces (APIs) are a set of protocols, 4. Exception handling: CLR provides a mechanism for handling exceptions that block of code. It allows you to create your own custom exceptions and throw
routines, and tools for building software applications. occur during the execution of .NET applications. 6. LINQ: C# includes Language-Integrated Query (LINQ), which provides a them when needed. The throw keyword is typically used in conjunction with
powerful way to query data from different sources using a single syntax. try-catch blocks to handle exceptions more effectively.
5. Architecture: The framework architecture is the high-level design of the 5. Type safety: CLR enforces type safety for .NET applications, preventing type For example, consider the following code:
framework, which defines how its components interact with each other. mismatches and other type-related errors. 7. Extension methods: C# allows developers to add new methods to existing
classes without modifying the original code. try
6. Documentation: Documentation is essential for any framework to ensure 6. Interoperability: CLR provides support for interoperability between .NET {
that developers can understand how to use it. code and code written in other languages, including COM and Win32 APIs. Some of the different types of applications that can be developed in C# int x = 10;
include: int y = 0;
7. Testing tools: Framework testing tools are used to test the functionality of 7. Debugging: CLR includes a debugging infrastructure that allows developers int result = x / y; // This will throw a DivideByZeroException
the framework and ensure that it works as expected. to debug .NET applications using tools such as Visual Studio. 1. Desktop applications }
2. Web applications catch (DivideByZeroException ex)
8. Development tools: Framework development tools are used to develop and 3. what is C# ? describe different features of C#. discuss 3. Mobile applications {
debug code within the framework. different types of application developed in C#. 4. Games Console.WriteLine("Error: " + ex.Message);
5. Machine learning }

finally using System; what is data type


{ using System.Threading; A property in C# is a member of a class that encapsulates a private field and a data type is a classification of data that specifies the type of values that a
Console.WriteLine("Finally block executed."); provides a way to read, write or compute its value. It allows the class to control variable can hold.
} class Program access to its private fields and provides a consistent interface for accessing 1. Value types: These are data types that store their values directly in memory.
predefined exception handling classes, { them. They include:
1. ArgumentException:. static void Main()
2. ArgumentNullException { Example program: - Boolean: Represents true or false values.
3. ArgumentOutOfRangeException Thread t1 = new Thread(new ThreadStart(CountUp));
4. DivideByZeroException Thread t2 = new Thread(new ThreadStart(CountDown)); using System; - Char: Represents a single character.
5. FileNotFoundException class Person
t1.Start(); { - Numeric types: These include byte, sbyte, short, ushort, int, uint, long, ulong,
5. what is multithreading ?describe life cycle of multithreading .write a t2.Start(); private string name; float, double, and decimal. They represent different sizes and ranges of
program to show the concept of multithreading in C# . public string Name numeric values.
Console.ReadKey(); {
Multithreading is a programming concept that allows a program to perform } get { return name; } - Enum: Represents a set of named constants.
multiple tasks concurrently, or simultaneously. It enables a program to run set { name = value; }
multiple threads of execution, each of which can perform a different task static void CountUp() } 2. Reference types: These are data types that store a reference to an object in
independently of the others. { } memory. They include:
for (int i = 1; i <= 10; i++)
The life cycle of multithreading involves several stages: { class Program - Object: The base class for all types in C#.
Console.WriteLine("Counting up: " + i); {
1. New: In this stage, a new thread is created but not yet started. Thread.Sleep(1000); static void Main(string[] args) - String: Represents a sequence of characters.
} {
2. Runnable: In this stage, the thread is ready to run and waiting for the CPU to } Person p = new Person(); - Array: Represents a collection of elements of the same type.
allocate resources. p.Name = "John"; - Class: A user-defined type that can contain fields, properties, methods, and
static void CountDown() Console.WriteLine("Name: " + p.Name); events.
3. Running: In this stage, the thread is executing its task. { }
for (int i = 10; i >= 1; i--) } - Interface: A user-defined type that defines a set of methods and properties
4. Blocked: In this stage, the thread is temporarily suspended and waiting for a { Different types of properties: that a class can implement.
resource to become available. Console.WriteLine("Counting down: " + i); 1. Read-Write Property: This type of property allows both read and write
Thread.Sleep(1000); access to its encapsulated field.
5. Terminated: In this stage, the thread has completed its task and is } 2.Read-Only Property: This type of property allows only read access to its Access modifiers
terminated. } encapsulated field. Access modifiers are keywords used in object-oriented programming languages
} 3. Write-Only Property: This type of property allows only write access to its to define the accessibility of class members such as fields, methods, and
Here's an example program that demonstrates the concept of multithreading encapsulated field. properties. These modifiers control the level of access that other classes or
in C#: what is property in C#.write a program to illustrate the use of property. 4. Computed Property: This type of property computes its value based on objects have to the members of a class.
describe different types of property with example. other fields or properties.
There are five types of access modifiers:

static void Main(string[] args) what is deligates in C# ? explain with example


1. Public: A public member can be accessed by any class or object. For {
example, a public method in a class can be called from any other class or Animal myAnimal = new Animal("lion");
Delegates in C# are similar to function pointers in C or C++. They are a type Inheritance
Console.WriteLine("The species of the animal is {0}.", that represents a reference to a method with a specific signature. Delegates Inheritance is a fundamental concept in object-oriented programming that
object.
myAnimal.species); can be used to pass methods as arguments to other methods, or to hold allows us to define a new class based on an existing class. The new class
myAnimal.Move(); references to methods for later invocation. inherits the properties and methods of the existing class and can also add new
2. Private: A private member can only be accessed within the same class where
} } } properties and methods of its own. Inheritance promotes code reuse, simplifies
it is declared. For example, a private field in a class can only be accessed by For example: code maintenance, and improves code organization.
methods within that same class.
C# Interface public static int Add(int a, int b)
Single inheritance: A derived class that inherits from only one base class.
3. Protected: A protected member can be accessed within the same class and Interface in C# is a blueprint of a class. It is like abstract class because all { Multi-level inheritance: A derived class that inherits from a base class and the
its subclasses. For example, a protected method in a class can be called from the methods which are declared inside the interface are abstract derived class itself becomes the base class for another derived class.
return a + b;
any subclass of that class. methods. It cannot have method body and cannot be instantiated. Hierarchical inheritance: A base class that serves as a parent class for two or
}
more derived classes.
4. Internal: An internal member can be accessed within the same assembly (or It is used to achieve multiple inheritance which can't be achieved by class. public static int Subtract(int a, int b) Multiple inheritance: A derived class that inherits from two or more base
module) where it is declared. For example, an internal field in a class can only It is used to achieve fully abstraction because it cannot have method { classes
be accessed by methods within the same assembly. body. Code Reusability: Inheritance allows us to reuse existing code by inheriting
return a - b; properties and methods from an existing class.
} Code Maintenance: Inheritance makes code maintenance easier by allowing us
5.protected internal : Variable or function declared protected internal can be Its implementation must be provided by class or struct. The class or to modify the base class and have the changes automatically reflected in the
accessed in the assembly in which it is declared. It can also be accessed within a struct which implements the interface, must provide the implementation static void Main(string[] args)
derived classes.
derived class in another assembly.
of all the methods declared inside the interface. { Code Organization: Inheritance improves code organization by grouping
internal access specifier in C#: related classes together in a hierarchical structure.
using System; Operation op = Add;
example:
namespace InternalAccessSpecifierExample public interface IShape int result = op(3, 4); // result is now 7 Disadvantages of Inheritance:
{ { Tight Coupling: Inheritance creates a tight coupling between the base class and
class Animal the derived class, which can make the code more difficult to maintain.
double Area { get; } op = Subtract;
{
double Perimeter { get; } Complexity: Inheritance can increase the complexity of the code by introducing
internal string species; result = op(3, 4); // result is now -1
public Animal(string species) } additional levels of abstraction.
{ }
this.species = species; public class Rectangle : IShape Fragility: Inheritance can make the code more fragile by creating dependencies
Delegates can also be used as parameters to methods, allowing us to pass in a
} { between the base class and the derived class.
method to be called as part of the method's implementation. This is known as a
internal void Move() public double Width { get; set; }
"callback" pattern, and is commonly used in event-driven programming. multilevel inheritance:
{ public double Height { get; set; }
Console.WriteLine("The {0} is moving.", species); using System;
} public double Area => Width * Height; Overall, delegates provide a powerful way to manipulate and pass around class Person
} public double Perimeter => 2 * (Width + Height); {
methods in C#, allowing for greater flexibility and code reuse.
class Program } protected string name;
{

public Person(string name) Console.WriteLine("Hi, my name is " + name + " and I'm studying
{ " + major + " in college"); 1. Default Constructor: This is a constructor that takes no parameters
For example, consider a class called Car with the following properties:
this.name = name; } and initializes the object with default values.
} }
public virtual void Introduce() 2. Parameterized Constructor: This is a constructor that takes one or c#
{ class Program
more parameters and initializes the object with those values. public class Car
Console.WriteLine("Hi, my name is " + name); {
} static void Main(string[] args) {
} { 3. Copy Constructor: This is a constructor that creates a new object by public string Make { get; set; }
class Student : Person Person person = new Person("John");
{ person.Introduce(); copying the values of an existing object. public string Model { get; set; }
protected int grade; public int Year { get; set; }
Student student = new Student("Jane", 10);
public Student(string name, int grade) : base(name) student.Introduce();
{ public Car(string make, string model, int year)
this.grade = grade; CollegeStudent collegeStudent = new CollegeStudent("Mary", 12,
A parameterized constructor is a constructor that takes one or more {
} "Computer Science");
public override void Introduce() collegeStudent.Introduce(); parameters. It is used to initialize the object with specific values passed Make = make;
{ as arguments. The parameters can be of any data type, including Model = model;
Console.WriteLine("Hi, my name is " + name + " and I'm in grade Console.ReadKey();
" + grade); } custom classes. Year = year;
} } } }
}

class CollegeStudent : Student Constructor C# Polymorphism


{
protected string major; In C#, constructor is a special method which is invoked automatically at The term "Polymorphism" is the combination of "poly" + "morphs" which
the time of object creation. It is used to initialize the data members of
new object generally. The constructor in C# has the same name as class means many forms. It is a greek word. In object-oriented programming,
public CollegeStudent(string name, int grade, string major) :
base(name, grade) or struct. we use 3 main concepts: inheritance, encapsulation and polymorphism.
{ There five types of constructors in C#.
this.major = major; 1.Default constructor There are two types of polymorphism in C#
} 2.Parameterized constructor
3. Copy Constructor
public override void Introduce() 4.Private Constructor
{ 5.Static Constructor
compile time polymorphism is achieved by method overloading and Operator overloading is a feature in C# that allows operators to Abstract Class: An abstract class is a class that cannot be }
operator overloading in C#. It is also known as static binding or early be used with user-defined types. It allows you to redefine the behavior instantiated, meaning you cannot create an object of that class. It is
binding. of an operator when it is used with objects of a particular class. used as a base class for other classes to inherit from. Abstract
Abstract Method: An abstract method is a method without any
Runtime polymorphism in achieved by method overriding which is also classes can contain abstract methods, which are methods without any
implementation. It is declared in an abstract class and must be
known as dynamic binding or late binding. implementation. Abstract classes are declared using the abstract
For example, consider a class called Vector2D that represents a two- implemented in the derived classes. Abstract methods are declared
Runtime Polymorphism Example keyword.
dimensional vector with an x and y component: using the abstract keyword and do not have a body.
Let's see a simple example of runtime polymorphism in C#.
Example:
c# Example:
using System;
public class Vector2D public abstract class Shape
public class Animal{
{ {
public virtual void eat(){ public abstract class Shape
public int X { get; set; } public abstract void Draw();
Console.WriteLine("eating..."); {
public int Y { get; set; } }
} public abstract void Draw();
} }
public Vector2D(int x, int y) public class Circle : Shape
public class Dog: Animal
{ {
{ public class Circle : Shape
X = x; public override void Draw()
public override void eat() {
Y = y; {
{ public override void Draw()
} // implementation for drawing a circle
Console.WriteLine("eating bread..."); {
}
} // implementation for drawing a circle
public static Vector2D operator +(Vector2D v1, Vector2D v2) }
}
{ public class Square : Shape
} public class TestPolymorphism }
return new Vector2D(v1.X + v2.X, v1.Y + v2.Y); {
{
} public override void Draw()
public static void Main() public class Square : Shape
} {
{ {
// implementation for drawing a square
Animal a= new Dog(); public override void Draw()
}
a.eat(); {
}
} // implementation for drawing a square
} }

Formal Parameter: A formal parameter is a parameter that is float f = i; //implicit conversion from int to float Invocation of methods refers to the process of calling or executing a a namespace is a way to organize and group related classes, structures,
specified in the method signature or declaration. It is also known as a method in a program. When a method is invoked, the program jumps to the interfaces, enums, and delegates. It provides a way to avoid naming
parameter variable. Formal parameters are used to define the input In this example, the integer value 10 is implicitly converted to a float method's code and executes it. The method may or may not return a value conflicts between different sets of code and allows for easier code
values that a method accepts. value without any explicit conversion code. depending on its implementation. Method invocation typically involves maintenance and organization. Namespaces can be declared using the
Example: passing one or more arguments (actual parameters) to the method, which are namespace keyword and can be nested within other namespaces. They
public void PrintName(string name) used by the method to perform its task. Once the method completes its are often used to group related functionality into separate logical units
2. Explicit Type Conversion: This type of conversion is done explicitly
execution, control is returned to the calling code. Method invocation is a and to provide a hierarchical structure to the code. Namespaces can be
{ by the programmer using casting operators. There are two types of
fundamental concept in object-oriented programming and is used extensively imported or referenced in other parts of the code using the using
Console.WriteLine("Hello, " + name); explicit type conversion: narrowing and widening.
in developing software applications. keyword, which allows for easier access to the types defined within
} the namespace.
In this example, `name` is the formal parameter of the `PrintName` a. Narrowing Conversion: This type of conversion is used to convert a Structure
method. larger data type to a smaller data type, which can result in data loss. a structure is a user-defined data type that encapsulates a set of related Jagged array
For example: data members and behaviors into a single unit. It is similar to a class, Jagged array is a array of arrays such that member arrays can be of
Actual Parameter: An actual parameter is the value that is passed to but with some key differences. Structures are value types, meaning that different sizes. In other words, the length of each array index can differ. The
a method when it is called. It is also known as an argument. Actual double d = 123.45; they are stored on the stack rather than the heap, and they do not elements of Jagged Array are reference types and initialized to null by default.
parameters are used to provide the input values to a method.
support inheritance. They are often used for small, simple data Jagged Array can also be mixed with multidimensional arrays. Here, the number
int i = (int)d; //explicit narrowing conversion from double to int
structures such as points, rectangles, and other geometric shapes. of rows will be fixed at the declaration time, but you can vary the number of
Structures can also include methods, properties, and events, just like columns.
Example: In this example, the double value 123.45 is explicitly converted to an classes. In Jagged arrays, user has to provide the number of rows only. If the user is also
PrintName("John"); integer value by truncating the decimal part, resulting in a potential going to provide the number of columns, then this array will be no more Jagged
In this example, `"John"` is the actual parameter that is passed to the loss of precision. Enumeration Array.
`PrintName` method. an enumeration is a user-defined data type that consists of a set of Syntax:
named constants, also known as enumerators. Each enumerator data_type[][] name_of_array = new data_type[rows][]
b. Widening Conversion: This type of conversion is used to convert a represents a distinct value of the enumeration type. Enumerations are Example:
Type conversion, also known as type casting, is the process of smaller data type to a larger data type, which does not result in data often used to define a set of related values that have a fixed number of int[][] jagged_arr = new int[4][]
converting a value from one data type to another. In C#, there are two loss. For example: possible values, such as the days of the week or the months of the year.
types of type conversion: implicit and explicit. Enumerations can be declared using the enum keyword and can include
int i = 10; custom values, attributes, and methods. They are often used in switch
statements and other control flow constructs to provide more In the above example, a single-dimensional array is declared that has 4
1. Implicit Type Conversion: This type of conversion is done float f = (float)i; //explicit widening conversion from int to float elements(rows), each of which is a 1-D array of integers
meaningful and readable code.
automatically by the compiler when there is no risk of data loss. For
example:
Namespace
int i = 10; Invocation of methods

an Array is a collection of elements of the same type that are c#


stored in contiguous memory locations. Arrays can be of any data int[] numbers = { 1, 2, 3, 4, 5 };
type, including primitive types like int, float, and char, as well as user- int thirdNumber = numbers[2]; // thirdNumber is now 3
defined types.

To declare an array in C#, you use square brackets after the data type In this example, we access the third element of the numbers array
and specify the number of elements in the array: using its index (which is 2 because of zero-indexing) and assign it to
the variable thirdNumber.
c#
int[] numbers = new int[5]; Arrays in C# are reference types, meaning that when you pass an
array to a method or assign it to another variable, you are actually
passing or assigning a reference to the original array in memory. This
In this example, we declare an integer array called numbers with 5 can have implications for how you manipulate arrays and how
elements. The new keyword is used to create a new instance of the changes to an array in one part of your code affect other parts of your
array with the specified size. code.

You can also initialize an array with values using an array initializer:

c#
int[] numbers = { 1, 2, 3, 4, 5 };

In this example, we declare an integer array called numbers and


initialize it with the values 1 through 5.

Arrays in C# are zero-indexed, meaning that the first element in the


array has an index of 0. You can access individual elements of an
array using square brackets and the element's index:

You might also like