It's saying that "type used in using statement must be implicitly convertible to System.IDisposable". That means, please Implement the IDisposable Interface to keep the class object within the using block.
Search This Blog
Q81-Q85
It's saying that "type used in using statement must be implicitly convertible to System.IDisposable". That means, please Implement the IDisposable Interface to keep the class object within the using block.
Q76-Q80
- IEnumerable exists in System.Collections Namespace.
- IEnumerable can move forward only over a collection, it can’t move backward and between the items.
- IEnumerable is best to query data from in-memory collections like List, Array, etc.
- While query data from a database, IEnumerable execute a select query on the server side, load data in-memory on a client-side and then filter data.
- IEnumerable is suitable for LINQ to Object and LINQ to XML queries.
- IEnumerable supports deferred execution.
- IEnumerable doesn’t support custom query.
- IEnumerable doesn’t support lazy loading. Hence not suitable for paging like scenarios.
- Extension methods support by IEnumerable takes functional objects.
- IQueryable exists in System. Linq Namespace.
- IQueryable can move forward only over a collection, it can’t move backward and between the items.
- IQueryable is best to query data from out-memory (like remote database, service) collections.
- While query data from a database, IQueryable execute the select query on the server side with all filters.
- IQueryable is suitable for LINQ to SQL queries.
- IQueryable supports deferred execution.
- IQueryable supports custom query using CreateQuery and Execute methods.
- IQueryable support lazy loading. Hence it is suitable for paging like scenarios.
- Extension methods support by IQueryable takes expression objects means expression tree.
Q71-Q75
Q66-Q70
.First() = If the sequence has at least one element, it returns the first one. No issues in having more than 1 element. If there are no elements it will throw error. .FirstOrDefault()n= Give me the first element, or the default value if there’s none. Default value is null for reference types and 0 for int, false for bool, etc.- Behavioral - These design patterns are specifically concerned with communication between objects.
- Chain of responsibility design pattern.
- Behaviour
- Iterator
- Structural - Make different pieces of systems in compatible with other part of System.
- Adaptor
- Facade
- Proxy
- Creational - It deals with the object creation mechanism.
- Singleton Design pattern
- Factory Design pattern
- Abstract Factory
Q61-Q65
static void Main(string[] args){int i;int j;j = 9;string s = getstring(out i, ref j);Console.WriteLine(i);Console.WriteLine(j);Console.Read();}private static string getstring(out int i, ref int j){j = 6;i = 4;return "app";}
Q56-Q60
| Array | Collection |
| 1. Array is Group of Homogeneous data type object. | 1. Collection is Group of Homogeneous and Heterogeneous data type object. |
| 2. Array is fixed in size. | 2. Collection is not fixed in size. |
| 3. Array is Strong type. | 3. Collection is not strong Type. |
| 4. There is no boxing and unboxing process on Array | 4. There is process of Boxing and Unboxing on Collection. |
| 5.We use Generic on Collection to make Collection as Strong type |
Q51-Q55
Q46-Q50
- public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
- private: The type or member can be accessed only by code in the same class or struct.
- protected: The type or member can be accessed only by code in the same class, or in a class that is derived from that class.
- internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
- protected internal: The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly.
- private protected: The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class.
Q41-Q45
- Iteration Control:
- IEnumerable: Simplifies Iteration using ForEach. Foreach uses IEnumberalbe behind the scene.
- IQueryable: Its a Queryable command to be executed on database side.
- IEnumerator: Provides manual control like MoveNext(), Reset() over iteration.
- Execution Context:
- IEnumerable: Executes In-Memory
- IQueryable: Executes query on datasource side. Transfer LINQ queries to SQL queries
- IEnumerator: Manages state of Iteration.
- Boxing is the conversion of the value type to an Reference(object) type.
- Unboxing refers to the conversion of the Reference(object) type to the value type
Q36-Q40
Q37. Explain DIP, Dependency Inversion Principle with example?
Q38. What is Static keyword in C#?
Q40. Explain cycle of Garbage collector.
-------------------------------------------------------------------------------------------------------------------------
Q36. Explain LSP, Liskov substitution principle with example?
Answer:
Liskov Substitution Principle:
- Derived types must be completely substitutable for their base types.
- It is extension of Open Close Principle.
- Basically, any child class should be able to do anything the parent can do.
Implementation guidelines
- No new exceptions can be thrown by the subtype.
- Clients should not known which specific subtype they are calling.
- New derived classes just extend without replacing the functionality of old classes.
this is the same example of concept B() = new D();
https://youtu.be/gnKx1RW_2Rk
-------------------------------------------------------------------------------------------------------------------------
Q37. Explain DIP, Dependency Inversion Principle with example?
Answer:
Dependency Inversion Principle: (DIP)
High level modules should not depend on low level modules, but both should depend on abstraction.
Abstraction should not depend on details, but details should depend on abstractions.
Adaptor design pattern is an example of DIP.
https://youtu.be/5WHKNOTqwsA
-------------------------------------------------------------------------------------------------------------------------
Q38. What is Static keyword in C#?
Answer:
The static keyword in C# language is used to declare static classes, static class members , static properties and even static constructor.
- Static class contain only static variables, static methods and static constructor.
- Object cannot be created for static class.
- Static class are sealed class means you cannot inherit static class from another class.
- Data members of static class can be directly accessed by using its class name.
- Static class and its members remain available till the lifetime of application.
- Non-Static class can have one or more static members and properties
- Static properties or fields of a non-static class is shared across all the instances. So, changes done by one instance would reflect in others.
- Static methods can be called without creating an object. You cannot call static methods using an object of the non-static class.
- The static methods can only call other static methods and access static members. You cannot access non-static members of the class in the static methods.
- A non-static class can have both static and non-static constructor. Static constructor would be called once during the application starting but we can keep on calling non static constructor as much we want.
Q39. What is IOC design principle?
-------------------------------------------------------------------------------------------------------------------------
- When the system runs out of physical memory.
- When the GC.Collect method is called manually.
- When allocated objects in memory need more space
Generation 0: When an object is allocated on the heap, it belongs to generation 0. It is the young generation, which contains short-lived objects like temporary variables. If newly allocated objects are larger in size, they will go on the large object heap in a generation 2 collection. GC occurs mostly in generation 0.
Generation 1: When objects survive from a garbage collection of generation 0, they go to generation 1. Objects in generation 1 serve as a buffer between short-lived and long-lived objects.
Generation 2: When objects survive from a garbage collection of generation 1, they go to generation 2. Objects in generation 2 serve as long-lived objects. If objects still survived in generation 2, they remain in generation 2 till they’re alive.


