Use of yield in C#

Normally, when we need to fetch the items from a collection we might create a temporary list to hold the retrieved items and return. But the use of yield, we can get a collection without the use of the temporary collection. Following is the simple example to retrieve list using return a temporary list. Here tmplist is used to store…

Continue Reading

Use Indexer in C#

Indexer helps to make an interface to the class easy way and get so many benefits from that we will understand indexer with an example. We are using classes with an aggregated or a composed collection of objects. For an example here, there are two classes Customer and Address. Customer has addresses and so we have to initialize objects of…

Continue Reading

Create custom view engine in MVC application

There are various third-party view engines available like Nhaml (pronounced enamel), spark, Brail, nVelocity but the most famous one is Razor used .cshtml and .vbhtml files to recognize views to render as simple HTML. You can create your own view engine and even use that with other view engines in one application. To use your custom view engine, you have…

Continue Reading

Improve Performance By Caching In MVC

In this article, you learn to implement caching and improve the performance of your MVC website. You can get the very impressive behavior of your site and faster than normally execute each time with lots of users request to your site. Generally, when the user requests an action to view all records from the particular table and just display as…

Continue Reading

Difference Between ON And WHERE Condition In Join

Usually, while you use joins with ON condition and some time as WHERE condition but what is the exact use of both? There is not any difference between ON and WHERE in INNER JOIN so you can see the actual difference in LEFT JOIN or RIGHT JOIN. To know the difference between ON and WHERE I tried with some simple examples.…

Continue Reading

What Is Dependency Injection?

Dependency Injection Dependency Injection (DI) is a pattern to hold dependencies between class and also to create loosely coupled classes. Before explaining, what are loosely coupled let’s understand tightly coupled classes. For example, there are two classes ClassA and ClassB defined as bonding between them. See the code as ClassA associated with ClassB So ClassB accessible or connected to ClassA…

Continue Reading

Execute Web Page Using Task Scheduler

Sometimes you have to create console application or window services to run based on schedule time and you just need to use Task Scheduler and set your time and it will be run automatically. It is easy to schedule console application or windows service with stand alone logic to run individually to access database or other services and do whatever…

Continue Reading

Send Bulk Emails Using Multi-Threading in .Net

If you use simple method call in for each loop to send bulk emails, for example, 1000 emails then you have been stuck in your application because of a single thread operated to send emails which are currently using the resources and thread of the application so to get the benefit of multi-threading is possible in .Net. To use multi-threading…

Continue Reading

Send Email Asynchronously in .Net

If you use synchronous mode to send an email then the process for to sending email start by calling a method, then the application has to wait to complete and that time application is blocked or halted. In contrast, asynchronous mode to call the method that you define as background and that method, return to an application immediately no matter…

Continue Reading

DateTime conversion and Snippets in MSSQL

Below you can find snippets for SQL to get data for different parts of date and time and all below queries tested in MS SQL server. DateTime Conversions MSSQL string to datetime conversion DateTime Snippets Year First day of this year First day of previous year Last day of previous year Last day of this year First day of next…

Continue Reading