1. What is the .NET Framework?
The .NET Framework is a comprehensive software development platform developed by Microsoft.
It includes a runtime environment called Common Language Runtime (CLR) and rich set of class libraries. It supports multiple programming languages such as C#, VB.NET, and F# and offers features like memory management, security and exception handling.
The .NET Framework is primarily used to create applications for Windows, But with the introduction of .NET Core and .NET 5, it can also be used to develop cross-platform applications as well.
2. What is 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 like memory management, Code verification, Security, garbage collection, and exception handling.
One of the key features of the CLR is the Just-In-Time (JIT) compiler.
When a .NET application is executed, The CLR uses the JIT compiler to convert the intermediate language (IL) code into a native machine code. This process happens during the execution, ensuring platform-specific optimization.
3. Explain the difference between Value types and reference types in .NET ?
In .NET data types are split up into 2 types :
- Value Types
- Reference Types
The primary difference between them lies on how they store their data and how they handle it in memory.
-> Value Types
directly contain their data and are stored 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, Therefore, changes made 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, store a reference to the actual data, which is stored on the heap. They include types such as :
(class/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, as 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 difference between value types and reference types is crucual 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 that provides classes and methods for handling input/output (I/O) operations.
These operations include reading from and writing to files, data streams, and communication with devices like hard drives and network connections.
The System.IO namespace includes a variety of classes that allows developers to interact with the file system and handle data streams efficiently. Some of the key classes include :
File : Provides static methods for creating, opening, deleting, and moving files.
Directory : Provides static methods for creating, moving and enumerating through directories and subdirectories
FileStream : Provides a stream for a file, supporting both synchronous and asynchronous read and write operations.
StreamReader and StreamWriter : These classes are for reading from and writing to character streams.
BinaryReader and BinaryWriter : These classes are for reading from and writing to binary streams.
> 5. How does the concept of attributes facilitate metadata in .NET?
Attributes in .NET are powerful constructs that allow developers to add metadata---additional descriptive information---to various elements in the code, such as classes, methods, properties and more...
This metadata can be accessed at runtim using reflection, allowing for dynamic and flexible programming.
Attributes have square brackets [] and are placed above the code elements they are related to. They can be utilised to control bahavior, provide additional information or introduce extra functionality.
[Serializable]
public class ExampleClass {
//Some code...
}
in the example above, the [Serializable] attribute is used to indicate that ExampleClass class can be serialized, a capability often curcial for storage or network transmission.
in addition to using predefined attributes such as Serialization, compilation, marshalling, etc...
.NET allows creating custom attributes to meet specific needs. This makes attributes a versatile and integral part of .NET, promoting declarative programming and code readability.
> 6. What is the difference between an exe and dll file in .NET?
An exe (executable) file contains an application's entry point and is intended to be executed directly. It represents a standalone program
public class Program {
public static void Main(string[] args) {
//This is the entry level...
}
}
On the other hand, a dll (dynamic-linl library) file contains ruseable code that can be referenced and use by mulitple applications.
It allows for code sharing and modular development.
public class Library {
public void SharedMethod () {
//This method can be used across different applications.
}
}
At runtime, The Common Language Runtime (CLR) loads and executes the exe's code and loads the corresponding dll into memory as needed when a class to a dll's functionality is made.
> 7. Explain the concept of Serialization and Deserialization in .NET ?
Serialization
is the process of converting an object into a stream of bytes to store or transmit it.
Deserialization
is the reverse process of reconstructing the object from the serialized bytes.
These mechanisms allow objects to be persisted, transferred over a network, or shared between different parts of an application.
> 8. What are the different types of exceptions in .NET and how are they handled ?
There are various types of exceptions in .NET, all of which derive from the base System.Exception class. Some commonly used exceptions include System.ApplicationException, System.NullReferenceException, System.IndexOutOfRangeException, System.DivideByZeroException and more....
In .NET exceptions are handled by using try-catch-finally blocks:
Try : The try block contains the code segment that may throw an exception.
catch : The catch block is used to capture and handle exceptions if they occur. You can have multiple catch block for a single Try block to handle different exceptions types separately.
finally : The finally block is optional and contains the code segment that should be executed irrespective of an error occuring. This generally conatins 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 designing and developing applications that can adapt to different cultures, Language, and regions.
Localization
is the process of customizing an application to a specific culture or locale.
In .NET, globalization and localization are supported through features like resource files, satellite, and the CultureInfo class, allowing applications to display localized and handle culture differenceses.
> 10. What is the difference between IActionResult and ActionResult in .NET ?
IActionResult
is an interface that represents the result of an action method.
It provides flexibility as you can return any object that implements this interface.
ActionResult
is a concrete implementation of IActionResult. It is a 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. Catch you later Nerds 👋
Top comments (0)