A delegate, which is also known as function pointer in C/C++, is reference type that used to hold the reference of method with specific signature, and invoke method through the delegate instance.
In .Net Delegate types are sealed and immutable type.
Types of Delegates
There are three types of delegates that can be used in C#.
- Single Delegate
- Multicast Delegate
- Generic Delegate
This article will present clear and succinct difference between two architecture presentation patterns i.e. MVP and MVC. Many developers are confused around what is the difference between these patterns.
Here are the key differences between the patterns:
- View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.
- Easier to unit test because interaction with the view is through an interface
- Usually view to presenter map one to one. Complex views may have multi presenters.
When I was started with Linq, I stuck many times on what the query will return, how to change return type of query? Sometimes our linq code need specific result as requirements.
We often write SQL query for database systems when it need to fetch stored data and we explicitly specify a set of columns to return, like:
The main goal for limiting the number of column is:
- Return only those necessary for query in order to improve performance.
- And, limit network traffic
The first statement return every column and row of the Employee table; whereas second will return only the three columns explicitly for all row, it save server and network resources.
Similarly select operator in LINQ query expressions provide the same task, and it provides powerful control over how and what data shape is returned from a query expression.
There are different ways a select clause can return results:
- As a single result value or element
- In an IEnumerable<T> where T is of the same type as the source items
- In an IEnumerable<T> where T is any existing type constructed in the select projection
- In an IEnumerable<T> where T is an anonymous type created in the select projection
- In an IEnumberable<IGrouping>, which is a collection of grouped objects that share a common key