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.
While using data access with the Entity Framework and LINQ, we always return List(), while some of developer prefer AsQueryable().
When we use AsQueryable, it just create a query, which is instruction to get a list. We can make further changes to the query later such as adding new Where clause that sent to the database level.
Returning IQueryable<T> has the advantage, that the execution is postponed until we start enumerating the result and we can compose the query with other queries and still get server side execution.
To reduce load times on our websites, we always cache some item in cookies and local storage. In this article some of differences between “Local Storage vs Cookies” is described.
Both Cookies and local storage serve difference purposes.
Choosing from these two
Cookies are primarily for reading server-side, local storage can only be read client-side.
So choosing from these two location to store data for our app, one question comes that, who needs this data : the client or the server?
If it’s our server need data, local storage isn’t so useful because we have to forward the data with each request by somehow (with Ajax or hidden form fields or something).
LocalStorage stays on the client, while cookies are sent with the HTTP header.
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
In this post, lets discuss Selecting single value in linq, such as :
- Numeric Result type
- Boolean result type
- Type <T> result type
One of the main task of a Linq query is to filter the results from a larger collection on some criteria. This is perform by Where operator, which tests each element within a source collection and returns only those elements that pass when tested against a given predicate expression.
A predicate is simply an expression that takes an element of the items in source collection and returns true or false.
The extension method for the Where operator is very simple; it iterates the source collection using a foreach loop, testing each element and return passed elements. Here is the actual code in the System.Linq library:
When we want to test some criteria on collection object’s element and depending upon result test result (true or false) we perform some operation on that collection or its elements, we should use predicate.
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.
Predicate<T> is a functional construct providing a convenient way of basically testing if something is true of a given T object.
In this post I discuss what is the difference between String and string in C#? (notice the case). What are the guidelines for the use of each? And what are the differences?
What is String and string?
string is an alias for System.String. So technically, there is no difference. It’s like int vs. System.Int32.
Since I’m started programming, I come across terms like const and static read only, which I used randomly based on my mood without even bother about why I am using these. and yesterday I try to find out what is meaning of this in programming grammar. I Google it and find an interesting question on stackoverflow(C#: Static readonly vs const).
I, C# developer, know the basics of C# like, declaration, condition, loops, operators, generics, anonymous types, lambdas, LINQ. Some of features there are in C# that I don’t know if it was there before I look at a stackoverflow question (Hidden Features of C#). In that question there are many answer that show how to use those features. You must visit that because you are a C# developer and you should know about that.