Q76. What is partial class in C#?
Q77. What is the difference between iqueryable (Iquerable) vs ienumerable? or AsEnumerable and AsQueryable?
Q78. Suppose you have a base class and a child class. Now while creating an instance of a child class which constructor will be called first?
Q79. What is the difference between Const and Readonly in C#?
Q80. What is finalize keyoword in C#?
=======================================================================
Q76. What is partial class in C#?
Answer:
In C#, you can split the implementation of a class, a struct, a method, or an interface in multiple .cs files using the partial keyword. The compiler will combine all the implementation from multiple .cs files when the program is compiled.
public partial class Employee
{
public void DoWork()
{
}
}
public partial class Employee
{
public void GoToLunch()
{
}
}
=======================================================================
Q77. What is the difference between iqueryable vs ienumerable?or AsEnumerable and AsQueryable?
Answer:
In LINQ to query data from database and collections, we use IEnumerable and IQueryable for data manipulation. IEnumerable is inherited by IQueryable, Hence IQueryable has all the features of IEnumerable and except this, it has its own features.
*As a general practice we must use IEnumerable when we are working with in memory collection(list, array) while we must use IQueryable when we are working with out of memory collections like files, database etc
IEnumerable
- 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
- 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.
=======================================================================
Q78. Suppose you have a base class and a child class. Now while creating an instance of a child class which constructor will be called first?
Answer:
Parent constructor will be called first.
=======================================================================
Q79. What is the difference between Const and Readonly in C#?
Answer:
Constants
1. Constants are static by default.
2. Values must be given to them at the time of declaration
3. They are compile time constant values.
Readonly
1. Usually they are declared but value is given to them in constructor.
2. They act as a run time constant values. Means they get their constant value during run time.
3. Readyonly variables can be given value both during declaration and in constructor.
=======================================================================
No comments:
Post a Comment