00 - Net Fundamental
00 - Net Fundamental
Net Fundamental
Normal-JIT (Default): - Normal-JIT compiles only those methods that are called at
runtime (cached takes more memory like ASP.NET and windows application)
Econo-JIT: - Econo-JIT compiles only those methods that are called at runtime (No
caching takes less memory like mob device and console applicaion)
Pre-JIT: - Pre-JIT compiles complete source code into native code in a single compilation
cycle. This is done at the time of deployment of the application
Garbage collector
Garbage collector is a back ground process which cleans unused managed resources.
c#
Ensures data types defined in two different languages gets compiled to a common data
type.
vb
Dim i As Integer
c#
int i;
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 2/14
8/8/24, 7:33 PM .Net Fundamental
Stack memory stores data types like int, double, boolean, Heap memory stores like string
and objects.
Value types contains actual data Reference types contains pointers and pointers point to
actual data
c#
int i =10;
bool b = true;
Customer obj= new Customer();
obj.Name = "Amit";
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 3/14
8/8/24, 7:33 PM .Net Fundamental
VR-B RV-U
c#
unboxing and boxing bring down performance because data has to jump between heap
and stack memory types
Casting where we convert one type of data type to other data type
c#
int i1 =10;
double d1 =i1; // implict casting
double d2 = 500.2;
int y = (int)d2; // explicit casting - data lose
Array ArrayList
c#
Generic collection
Generic collection is strongly typed and flexible. It has better performance as compared to
ArrayList
c#
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 5/14
8/8/24, 7:33 PM .Net Fundamental
c#
c#
Importance of task
parallel processing
return, result, cancel, Async, Await
c#
try{
int z =1/0;
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 6/14
8/8/24, 7:33 PM .Net Fundamental
} catch(Exception ex){
Console.WriteLine("Exception");
}
finally
{
Console.WriteLine("Clean up code");
}
What is finally
c#
Main(){
Calculate(10,5, out add, out sub);
}
Calculate(int n1, int n2, out int add, out int sub){
add = n1 + n2;
sub = n1 - n2;
}
ref
c#
out
c#
Delegates are callbacks which helps to communicate between async and parallel execution
Example: if you have two parallel process and if you need to send data to other parallel
process. In this scenario delegates will be helpful
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 8/14
8/8/24, 7:33 PM .Net Fundamental
Multicast delegates
Multicast delegates is nothing but basically multiple methods runs at one moment of time
Example: Broadcast error message via email, file log, sms, event log etc
c#
class Example
{
public delegate void MyDelegate();
void button_click()
{
MyDelegate mydele =null;
mydele += this.Method1;
mydele += this.Method2;
mydele.Invoke();
}
}
Anonymous method
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 9/14
8/8/24, 7:33 PM .Net Fundamental
Events
Event use delegates internally. They encapsulate delegates and make them safe
c#
void button_click()
{
MyDelegate mydele =null;
mydele += this.Method1;
mydele += this.Method2;
mydele = null; // throw exception
}
Dispose object
Using directives
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 10/14
8/8/24, 7:33 PM .Net Fundamental
c#
using System;
using System.IO
using Namespace = Application.Services;
These are used to import namespaces (or create aliases for namespaces or types). These go
at the top of the file, before any declarations
Using statements
c#
This can only be used with types that implement IDisposable, and is syntactic sugar for a
try/finally block which calls Dispose in the finally block
c#
Is equivalent to:
c#
finally
{
if(obj != null)
{
obj.Dispose();
}
}
Finalize Dispose
Finalize
c#
using System;
namespace DemoApplication{
public class Demo{
~Demo(){
Console.WriteLine("Finalize called");
}
}
}
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 12/14
8/8/24, 7:33 PM .Net Fundamental
Dispose
some resources like windows handles, database connections, network connections, files, etc.
which cannot be collected by the Garbage Collector. If we want to explicitly release some
specific objects then this is the best to implement IDisposable and override the Dispose()
method of IDisposable interface
c#
using System;
namespace DemoApplication{
public class Demo : IDisposable{
private bool disposed = false;
public void Dispose(){
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing){
if (!disposed){
if (disposing){
//clean up managed objects
}
//clean up unmanaged objects
disposed = true;
}
}
}
}
c#
GC.Collect(0);
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 13/14
8/8/24, 7:33 PM .Net Fundamental
PREVIOUS NEXT
https://amitpnk.github.io/interview-questions/#/./DotNetFundamental 14/14