Q26. What are the two different types of memory in C#?
Q27. How we can call Garbage collector explicitly?
Q28. Write a linq query to use AsQuerable while getting multiple records? Also how to use AsQuerable in case of joins?
Q29. What are the advantages of Tasks over Thread? Why Tasks came in picture when we have thread in C#?
Q30. Difference between String and StringBuilder class?
------------------------------------------------------------------------------------------------------------------------------------------
Q26. What are the two different types of memory in C#?
Answer:
Stack and Heap.
GC works only on Heap. GC is not required on Stack Memory because this get auto deallocated once the variable goes out of scope.
Value types of variables like int, bool, float, short, enum, struct are part of Stack memory.
Reference types like string, objects, classes are part of heap memory
------------------------------------------------------------------------------------------------------------------------------------------
Q27. How can we call Garbage collector explicitly?
Answer:
Garbage collector can be called explicitly with GC.Collect().
GC.Collect(0): Will clear zero generation objects
GC.Collect(1): Will clear zero and 1st generation objects.
GC.Collect(2): Will clear all generation objects (Zero, 1st, 2nd)
Although we don't need this as Garbage collector take care of collecting in destructor only by calling GC.Finalize. GC.Finalize cannot be called explicitly.
for managing unmanaged code, we use Dispose method.
------------------------------------------------------------------------------------------------------------------------------------------
Q28. Write a linq query to use AsQuerable while getting multiple records? Also how to use AsQuerable in case of joins?
Answer:
------------------------------------------------------------------------------------------------------------------------------------------
Q29. What are the advantages of Tasks over Thread? Why Tasks came in picture when we have thread in C#?
Answer:
Task is a newer concept than Thread.
- Task can return a result. There is no direct mechanism to return the result from thread.
- We can chain tasks together to execute one after the other.
- Establish a parent/child relationship when one task is started from another task.
- Task support cancellation through the use of cancellation tokens.
- Asynchronous implementation is easy in task, using’ async’ and ‘await’ keywords.
------------------------------------------------------------------------------------------------------------------------------------------
Q30. Difference between String and StringBuilder class?
Answer:
Stringbuilder is mutable while string not mutable. Mutable means when we try to change the value of original object it will adopt those changes.
When we make changes in value of a string variable it create a new instance of it as it is immutable and thus it become a costly process from memory point of view but stringbuilder doesn't create any new instance.
Append is the method used in stringbuilder.
StringBuilder sbMyValue = new StringBuilder("");
sbMyValue.Append("Hello Visitor");
sbMyValue.Append("How Are You ??");
------------------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment