1. What is the .NET Framework?
.NET Framework is a comprehensive software development platform developed by Microsoft.
It includes a runtime environment called the common language runtime (CLR) and a rich set of class libraries. It supports multiple programming languages, such as C#, VB.NET and F#, and provides functions such as memory management, security and exception handling.
The .NET Framework is primarily used for building Windows applications, but with the introduction of .NET Core and .NET 5, it can also be used to develop cross-platform applications.
2. What is the Common Language Runtime (CLR)?
The common language runtime (CLR) is the execution environment provided by the .NET Framework. It manages the execution of .NET applications, providing services such as memory management, code verification, security, garbage collection, and exception handling.
One of the CLR’s primary features is a just-in-time (JIT) compiler.
When executing a .NET application, the CLR uses a JIT compiler to convert intermediate language (IL) code into native machine code. This process occurs during execution, ensuring platform-specific optimization.
3.Explain the difference between value types and reference types in .NET?
In .NET, data types are divided into two types:
- value type
- Reference type
The main difference between them is how data is stored and processed in memory.
-> Value Types
Contains their data directly and stores it on the stack.
They include primitive types such as: (int/bool/float/double/char/decimal/enum).
When a value is assigned to a new variable, a copy of the value is made, so changes to one variable do not affect the other
int x = 10;
int y = x;
y = 20;
// Here x is not effected, x still 10 and y equal 20.
-> Reference Types
On the other hand, a reference to the actual data is stored, which is stored on the heap. They include the following types:
(category/interface/delegate/string/array).
When a reference type is assigned to a new variable, the interface is copied, not the actual data. Therefore, changes made to one variable will affect the other variable because they both point to the same data.
class Person {
public string Name {get; set;}
}
Person person1 = new Person {Name = "Resh"};
Person person2 = person1;
person2.Name = "Mezz";
Console.WriteLine(person1.Name); // output : Mezz;
Console.WriteLine(person2.Name); // output : Mezz;
Understanding the differences between value types and reference types is critical for efficient memory management and performance optimization in .NET applications.
> 4. What is the purpose of the System.IO namespace in .NET?
The System.IO namespace in .NET is a fundamental part of the framework, providing classes and methods for handling input/output (I/O) operations.
These operations include reading and writing files, data streams, and communicating with devices such as hard drives and network connections.
The System.IO namespace contains various classes that allow developers to interact with file systems and efficiently handle data streams. Some key lessons include:
document : Provides static methods for creating, opening, deleting and moving files.
Table of contents : Provides static methods for creating, moving, and enumerating directories and subdirectories
file stream : Provides streams for files, supporting synchronous and asynchronous read and write operations.
StreamReader and StreamWriter : These categories are used for reading and writing character streams.
BinaryReader and BinaryWriter : These categories are used for reading and writing binary streams.
> 5. How does the concept of properties facilitate metadata in .NET?
Properties in .NET are powerful constructs that allow developers to add metadata (additional descriptive information) to various elements in their code, such as classes, methods, properties, etc…
This metadata can be accessed at runtime using reflection, allowing dynamic and flexible programming.
Properties have square brackets [] and placed above its associated code element. They can be used to control behavior, provide additional information or introduce additional functionality.
[Serializable]
public class ExampleClass {
//Some code...
}
In the above example, [Serializable] Attribute is used to indicate that the ExampleClass class can be serialized, which is usually necessary for storage or network transmission.
In addition to using predefined properties (such as serialization, compilation, marshalling, etc.)…
.NET allows the creation of custom properties to meet specific needs. This makes properties a universal and integral part of .NET, promoting declarative programming and code readability.
> 6. What is the difference between exe files and dll files in .NET?
An exe (executable) file contains the entry point for an application and is intended for direct execution. it represents an independent program
public class Program {
public static void Main(string[] args) {
//This is the entry level...
}
}
On the other hand, dll (dynamic link library) files contain reusable code that can be referenced and used by multiple applications.
It allows code sharing and modular development.
public class Library {
public void SharedMethod () {
//This method can be used across different applications.
}
}
At execution time, the common language runtime (CLR) will load and execute the exe’s code, and load the corresponding dll into memory as needed when creating classes for the dll function.
> 7.Explain the concepts of serialization and deserialization in .NET?
Serialization
It is the process of converting objects into a stream of bytes for storage or transmission.
Deserialization
Is the reverse process of reconstructing an object from serialized bytes.
These mechanisms allow objects to be persisted, transferred over the network, or shared between different parts of the application.
> 8. What are the different types of exceptions in .NET and how to deal with them?
There are many types of exceptions in .NET, all of which are derived from the System.Exception base class. Some commonly used exceptions include System.ApplicationException, System.NullReferenceException, System.IndexOutOfRangeException, System.DivideByZeroException, etc…
In .NET, exceptions are handled using try-catch-finally blocks:
try : The try block contains code segments that may throw exceptions.
catch :catch block is used to catch and handle exceptions that occur. A single Try block can have multiple catch blocks to handle different exception types respectively.
at last The :finally block is optional and contains a section of code that should be executed regardless of an error. This usually includes cleanup code…
try{
int[] arr = {1,2,3}
Console.WriteLine(arr[3]); //This will throw an IndexOutOfRangeException..
}
catch(IndexOutOfRangeException ex){
Console.WriteLine("Exception : {ex.Message}")
}
finally{
Console.WriteLine("This line is always executed wether the exception is thrown or not");
}
> 9. What is the role of globalization and localization in .NET?
Globalization
Refers to the design and development of applications that can adapt to different cultures, languages and regions.Localization
It is the process of customizing an application for a specific culture or region.
In .NET, globalization and localization are supported through features such as resource files, satellites, and CultureInfo classes, allowing applications to display localization and handle cultural differences.
> 10. What is the difference between IActionResult and ActionResult in .NET?
IActionResult
It is an interface that represents the results of operation methods.
It provides flexibility because you can pass back any object that implements this interface.ActionResult
It is the specific implementation of IActionResult. It is the base class for results such as ViewResult, JsonResult, RedirectResult, etc., and provides additional type safety and functionality.
That’s it for now! Keep coding and stay awesome. See you later nerds 👋