fundamentals Flashcards
What are the steps involved when we run the dot Net code?
Any dot Net code such as C# will first convert to an IL code. IL code is a partially compiled code. This partially compiled code will then be loaded by CLR to be converted to a machine code. This machine code will be executed by the JIT.
What is CLR?
When the IL code is generated, CLR will convert it to the machine’s native language. It also does other operations such as garbage collection.
What is CTS?
Common Type System: When we write two programs, one in c# and other one in VB. we can cross use the code. To enable cross using of the code, we have CTS where the data types defined in two different languages gets compiled to a common data type.
What is CLS?
Common Language Specifications is the specification which should be followed by any dot Net language so that when once program is used in another language program it will not get into any issue.
Provide a demo on how IL, CLR, CTS and CLS work?
Create a c# program and build it.
Open the output file using ildasm.exe. You can see the IL code.
Write one more program in VB. Open in ildasm.exe.
See that the int in C3 and vb is converted to int32. This is CTS.
in C#, create two variables, v1 and V2. when we try to use these in VB, it will not work becase VB is a case-insensitive language and we have vioalated CLS.
What is an assembly? What are types of assembly?
When we build an application, we get either dll or exe. this is called assembly. Exe will have its own address space. dll has to be laoded.
How do you link dll in exe.
using dll name. add dll as a reference.
What is an App domain?
App domain is a logical isolated container inside a process address space. In app doamin, we can load a peice code/dll in a isolated manner.
We can add permission to the app domin. Example, there is a dll or class which shoould not create a file. Then we can create a permission and pass that permission in CreateDomiain method. We can also unlaod a domain.
What is an App domain?
App domain is a logical isolated container inside a process address space. In app doamin, we can load a peice code/dll in a isolated manner.
We can add permission to the app domin. Example, there is a dll or class which shoould not create a file. Then we can create a permission and pass that permission in CreateDomiain method. Then call CreateInstanceAndUnwrap(assemblyName) We can also unlaod a domain.
What is managed and unmanaged code?
Managed code runs under CLR. Unmanaged code runs under its own runtime (C++). CLR managed GC, CLS, CAS etc.
How to see the Garage Collector?
CLRProfile.exe available in MSFT site.
What is a GC?
dot Net is an managed code and CLR takes care of clearing the objects. This process is called GC.
The way it works is that it will have gen0, gen1, gen2.
Any new object created will be in gen0. GS is a background thread and it will check the gen0 bucket. If objects are there and if the objects are used then they will be moved to the Gen1 bucket, Unused objects will be deleted. Next time, when the GC checks these, if the objects in Gen1 is required then it will move to Gen2.
WHy do we need this? This will help to optimzse the GC job. GC will frequenlt chec the Gen0 bucket.
Also having too many objects in Gen2 is not good. This will increase the process memory.
What is IDisposable?
If we want to clean up the resources in dot Net class, we cannot clear it as we do it in c++. this is becasue when GC find that the class is having a destructor, it will move the objects to the Gen 1 and Gen2. Hence, we need to used IDisposable interface. Inherit from IDisposable then implement Dispose method. Inside DIspose method call GC.SupressFinalaise();
public class hey : IDisposable { ~hey() {}
dispose(){ GC.SupressFinalise() } }
What is a strong reference and weak reference.
Suppose I have an exe and a dll. I will add a reference of the dll to the exe and invoke the class method of the dll.
The problem is that I can create a same dll and class name and replace this dll. The exe will load this dll.
To avoid this, we will use signing.
In weak reference, the dlls are laoded based on the class name and namespace names.
Why is a byte datatype?
Each characters are represented as 0 or 1 (bits). Byte is 2^8. 8 bits is 1 byte. Max - 255 and Min 0. Its unsigned/
Why is a byte datatype?
Each characters are represented as 0 or 1 (bits). Byte is 2^8. 8 bits is 1 byte. MaxValue - 255 and Min 0. Its unsigned/
What is difference between float, double and decimal?
float - 7 decimals
double - 16
decimal - 29