.NET interview: What is a CLR (Common Language Runtime)?
Often there is a need for different languages to communicate with each other at run time. For e.g. A class may be written in one language and its derived class may be written in a different language. Common Language Runtime is a run time environment for .NET. These different languages are integrated and can communicate easily because language compilers and tools that target the runtime use a common type system defined by the runtime.
Features or Functionalities offered by CLR:-
- Garbage collection for managing life of objects.
- Enables Cross language inheritance as explained in example above.
- Syntax and keywords similar to C and C++
Interview Question :: garbage collector in .NET?
When should you call the garbage collector in .NET?
Garbage collection is a process of releasing the memory used by the objects, which are no longer referenced. This is done in different ways and different manners in various platforms and languages. We will see how garbage collection is being done in .NET.
C# interview questions and answers
I need to restrict a class by creating only one object throughout the application. How can I achieve this?
We can declare the constructor of the class as either protected or as private
int? d = 1; Type testType = d.GetType(); will result…
NOTE: This is objective type question, Please click question title for correct answer.
How can you make your machine shutdown from your program?
Process.Start("shutdown", "-s -f -t 0");
What is the use of unsafe keyword in C#?
In C# the value can be directly referenced to a variable, so there is no need of pointer. Use of pointer sometime crashes the application. But C# supports pointer, that means we can use pointer in C#.
The use of pointer in C# is defined as a unsafe code. So if we want to use pointer in C# the pointer must be present in the body of unsafe declaration. But pointer does not come under garbage collection.
Example:-
unsafe
{
int a, *b;
a = 25;
b = &a;
Console.WriteLine("b= {0}",b);//returns b= 25
}
What is difference between var and Dynamic ?
Var word was introduced with C#3.5(specifically for LINQ) while dynamic is introduced in C#4.0. variables declared with var keyword will get compiled and you can have all its related methods by intellisense while variables declared with dynamic keyword will never get compiled. All the exceptions related to dynamic type variables can only be caught at runtime.
What is dynamic keyword ?
Its newly introduced keyword of C#4.0. To indicate that all operations will be performed runtime.
What will happen if you declare a variable named "checked" with any data type?
Compiler will throw an error as checked is a keyword in C# So It cannot be used as variable name. Checked keyword is used to check the overflow arithmetic checking.
What are anonymous methods?
Anonymous methods are another way to declare delegates with inline code except named methods.
Restrictions of yield in try-catch.
While using yield keyword, mainly two restrictions are observed.
First is , we can’t use yield in finally.
Second is , we can’t place yield keyword in the catch block if try contains more than one catch blocks.
With yield break statement, control gets …
NOTE: This is objective type question, Please click question title for correct answer.
What first action compiler will take on detection of iterator ?
As soon as compiler will detect iterator, it will automatically generate current, MoveNext and Disposemethods of the IEnumerator or IEnumerator(T) type.