Which of the following operators cannot use operator overloading?
Anonymous Quiz
13%
operator ++
11%
operator &
10%
operator ||
65%
operator true
❓Discuss what garbage collection is and how it works. Provide a code example of how you can enforce garbage collection in .NET
Garbage collection is a low-priority process that serves as an automatic memory manager which manages the allocation and release of memory for the applications. Each time a new object is created, the common language runtime allocates memory for that object from the managed Heap. As long as free memory space is available in the managed Heap,the runtime continues to allocate space for new objects. However, memory is not infinite, and once an application fills the Heap memory space, garbage collection comes into play to free some memory.
When the garbage collector performs a collection, it checks for objects in the managed Heap that are no longer being used by the application and performs the necessary operations to reclaim the memory. Garbage collection will stop all running threads, it will find all objects in the Heap that are not being accessed by the main program and delete them. It will then reorganize all the objects left in the Heap to make space and adjust all the Pointers to these objects in both the Stack and the Heap.
To enforce garbage collection in your code manually, you can run the following command (C#):
Garbage collection is a low-priority process that serves as an automatic memory manager which manages the allocation and release of memory for the applications. Each time a new object is created, the common language runtime allocates memory for that object from the managed Heap. As long as free memory space is available in the managed Heap,the runtime continues to allocate space for new objects. However, memory is not infinite, and once an application fills the Heap memory space, garbage collection comes into play to free some memory.
When the garbage collector performs a collection, it checks for objects in the managed Heap that are no longer being used by the application and performs the necessary operations to reclaim the memory. Garbage collection will stop all running threads, it will find all objects in the Heap that are not being accessed by the main program and delete them. It will then reorganize all the objects left in the Heap to make space and adjust all the Pointers to these objects in both the Stack and the Heap.
To enforce garbage collection in your code manually, you can run the following command (C#):
System.GC.Collect();
📝 Is operator overloading supported in C#?
A user-defined type can overload a predefined C# operator. That is, a type can provide the custom implementation of an operation in case one or both of the operands are of that type.
The above function implements the addition operator (+) for a user-defined class Box. It adds the attributes of two Box objects and returns the resultant Box object.
A user-defined type can overload a predefined C# operator. That is, a type can provide the custom implementation of an operation in case one or both of the operands are of that type.
The above function implements the addition operator (+) for a user-defined class Box. It adds the attributes of two Box objects and returns the resultant Box object.
In multithread programming, which of the followings is not using Thread Pool?
Anonymous Quiz
18%
BackgroundWorker class
26%
Asynchronous delegate
35%
Thread class
21%
Task class
❓Explain what LINQ is
LINQ is an acronym for Language Integrated Query, and was introduced with Visual Studio 2008. LINQ is a set of features that extends query capabilities to the .NET language syntax by adding sets of new standard query operators that allow data manipulation, regardless of the data source. Supported data sources are: .NET Framework collections, SQL Server databases, ADO.NET Datasets, XML documents, and any collection of objects that support
LINQ is an acronym for Language Integrated Query, and was introduced with Visual Studio 2008. LINQ is a set of features that extends query capabilities to the .NET language syntax by adding sets of new standard query operators that allow data manipulation, regardless of the data source. Supported data sources are: .NET Framework collections, SQL Server databases, ADO.NET Datasets, XML documents, and any collection of objects that support
IEnumerable
or the generic IEnumerable<T>
interface, in both C# and Visual Basic. In short, LINQ bridges the gap between the world of objects and the world of data.📝 Why to use lock statement in C#?
The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released.
The lock keyword calls Enter at the start of the block and Exit at the end of the block. lock keyword actually handles Monitor class at back end.
The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released.
The lock keyword calls Enter at the start of the block and Exit at the end of the block. lock keyword actually handles Monitor class at back end.
Class A has [Serializable()] attribute. When is [Serializable] checked?
Anonymous Quiz
29%
At C# compile time
41%
At CLR runtime
19%
At JIT compile time
11%
At Linking
❓Discuss the difference between constants and read-only variables
While constants and read-only variable share many similarities, there are some important differences:
- Constants are evaluated at the compile-time, while the read-only variables are evaluated at the runtime.
- Constants support only value-type variables, while read-only variables can hold reference type variables.
- Constants should be used when the value is not changing during the runtime, and read-only variables are used mostly when their actual value is unknown before the runtime.
While constants and read-only variable share many similarities, there are some important differences:
- Constants are evaluated at the compile-time, while the read-only variables are evaluated at the runtime.
- Constants support only value-type variables, while read-only variables can hold reference type variables.
- Constants should be used when the value is not changing during the runtime, and read-only variables are used mostly when their actual value is unknown before the runtime.
The followings are some examples of integer arrays. Which expression is not valid in C#?
Anonymous Quiz
5%
int[] a = new int[10];
7%
int[][] c = new int[10][];
43%
int[][][] cc = new int[10][2][];
6%
int[,] b = new int[10, 2];
39%
int[, , ,] d = new int[10, 2, 2, 2];
Which of the following statements is true about C# anonymous type?
Anonymous Quiz
22%
Anonymous type can add new property once it is created
6%
Anonymous type can add an event
27%
You can use a delegate for a method in anonymous type
45%
Anonymous type is an immutable type
❓Explain the difference between managed and unmanaged code
MANAGED CODE is a code created by the .NET compiler. It does not depend on the architecture of the target machine because it is executed by the CLR (Common Language Runtime), and not by the operating system itself. CLR and managed code offers developers few benefits, like garbage collection, type checking and exceptions handling.
On the other hand, UMANAGED CODE is directly compiled to native machine code and depends on the architecture of the target machine. It is executed directly by the operating system. In the unmanaged code, the developer has to make sure he is dealing with memory usage and allocation (especially because of memory leaks), type safety and exceptions manually. In .NET, Visual Basic and C# compiler creates managed code. To get unmanaged code, the application has to be written in C or C++.
MANAGED CODE is a code created by the .NET compiler. It does not depend on the architecture of the target machine because it is executed by the CLR (Common Language Runtime), and not by the operating system itself. CLR and managed code offers developers few benefits, like garbage collection, type checking and exceptions handling.
On the other hand, UMANAGED CODE is directly compiled to native machine code and depends on the architecture of the target machine. It is executed directly by the operating system. In the unmanaged code, the developer has to make sure he is dealing with memory usage and allocation (especially because of memory leaks), type safety and exceptions manually. In .NET, Visual Basic and C# compiler creates managed code. To get unmanaged code, the application has to be written in C or C++.
📝 What is the difference between dispose and finalize methods in C#?
Finalizer and Dispose both are used for same task like to free unmanaged resources but have some differences see.
Finalize:
🔸 Finalize used to free unmanaged resources those are not in use like files, database connections in application domain and more, held by an object before that object is destroyed.
🔸 In the Internal process it is called by Garbage Collector and can't called manual by user code or any service.
🔸 Finalize belongs to System.Object class.
🔸 Implement it when you have unmanaged resources in your code, and make sure that these resources are freed when the Garbage collection happens.
Dispose:
🔸 Dispose is also used to free unmanaged resources those are not in use like files, database connections in Application domain at any time.
🔸 Dispose explicitly it is called by manual user code.
🔸 If we need to dispose method so must implement that class by IDisposable interface.
Finalizer and Dispose both are used for same task like to free unmanaged resources but have some differences see.
Finalize:
🔸 Finalize used to free unmanaged resources those are not in use like files, database connections in application domain and more, held by an object before that object is destroyed.
🔸 In the Internal process it is called by Garbage Collector and can't called manual by user code or any service.
🔸 Finalize belongs to System.Object class.
🔸 Implement it when you have unmanaged resources in your code, and make sure that these resources are freed when the Garbage collection happens.
Dispose:
🔸 Dispose is also used to free unmanaged resources those are not in use like files, database connections in Application domain at any time.
🔸 Dispose explicitly it is called by manual user code.
🔸 If we need to dispose method so must implement that class by IDisposable interface.
What is the result of variable a and b?
Anonymous Quiz
22%
a=true, b=true
34%
a=true, b=false
19%
a=false, b=true
26%
a=false, b=false
❓What are the fundamental concepts of OOP?
OOP stands for Object-Oriented Programming and the following are the fundamental concepts:
- Encapsulation: It is the internal representation of an object which is hidden from the outside view of an object’s definition. Only required information is accessed while the other data are hidden.
- Abstraction: It is defined as the process of identifying critical behavior, eliminating the irrelevant details and data of an object.
- Inheritance: It is defined as the process of creating new classes from another class. This can be achieved by accessing, modifying, and extending the behavior of the objects in their parent class.
- Polymorphism: It is a term used for describing one name in many forms. It can be achieved through the same name but different implementations.
https://youtu.be/m_MQYyJpIjg
OOP stands for Object-Oriented Programming and the following are the fundamental concepts:
- Encapsulation: It is the internal representation of an object which is hidden from the outside view of an object’s definition. Only required information is accessed while the other data are hidden.
- Abstraction: It is defined as the process of identifying critical behavior, eliminating the irrelevant details and data of an object.
- Inheritance: It is defined as the process of creating new classes from another class. This can be achieved by accessing, modifying, and extending the behavior of the objects in their parent class.
- Polymorphism: It is a term used for describing one name in many forms. It can be achieved through the same name but different implementations.
https://youtu.be/m_MQYyJpIjg
YouTube
Fundamental Concepts of Object Oriented Programming
This video reviews the fundamental concepts of Object Oriented Programming (OOP), namely:
Abstraction, which means to simplify reality and focus only on the data and processes that are relevant to the application being built; Encapsulation meaning that data…
Abstraction, which means to simplify reality and focus only on the data and processes that are relevant to the application being built; Encapsulation meaning that data…
📝 What is the difference between is and as operators in C#?
The is operator checks if an object can be cast to a specific type.
The is operator checks if an object can be cast to a specific type.
if (someObject is StringBuilder) ...The as operator attempts to cast an object to a specific type, and returns null if it fails.
StringBuilder b = someObject as StringBuilder;
if (b != null) ...
When defining a class using C# Generics, which of the followings is invalid?
Anonymous Quiz
29%
class MyClass where T : struct
6%
class MyClass where T : class
8%
class MyClass where T : IComparable
12%
class MyClass where T : MyBase
45%
All of the above are correct
❓State the difference between is and as operators in C#
The difference between is and as an operator in C# is that is the operator is used for checking the compatibility of an object for a given type and returning to the Boolean for the results.Whereas as the operator is used for casting of an object to a type or to a class.
https://youtu.be/IKmRtJcRX_I
The difference between is and as an operator in C# is that is the operator is used for checking the compatibility of an object for a given type and returning to the Boolean for the results.Whereas as the operator is used for casting of an object to a type or to a class.
https://youtu.be/IKmRtJcRX_I
YouTube
IS vs AS Keyword | C# Interview Questions with Answers | Csharp Interview Questions | IS vs AS in C#
See our other Step by Step video series below :-
For more such videos visit http://www.questpond.com
For more such videos subscribe https://www.youtube.com/questpondvideos
See our other Step by Step video series below :-
JavaScript Interview Questions: h…
For more such videos visit http://www.questpond.com
For more such videos subscribe https://www.youtube.com/questpondvideos
See our other Step by Step video series below :-
JavaScript Interview Questions: h…