Nizamuddin Siddiqui has Published 2307 Articles

What is the use of static constructors in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:52:15

2K+ Views

A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced.Static constructors are useful when creating wrapper classes for unmanaged code, when ... Read More

How can we get the client's IP address in ASP.NET MVC C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:45:33

3K+ Views

Every machine on a network has a unique identifier. Just as you would address a letter to send in the mail, computers use the unique identifier to send data to specific computers on a network. Most networks today, including all computers on the internet, use the TCP/IP protocol as the ... Read More

What is the difference between | and || operators in c#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:43:30

732 Views

|| is called logical OR operator and | is called bitwise logical OR but the basic difference between them is in the way they are executed. The syntax for || and | the same as in the following −bool_exp1 || bool_exp2bool_exp1 | bool_exp2Now the syntax of 1 and 2 looks similar ... Read More

How to install a windows service using windows command prompt in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:39:35

2K+ Views

Step 1 −Create a new windows service application.Step 2 −For running a Windows Service, you need to install the Installer, which registers it with the Service Control Manager. Right click on the Service1.cs[Design] and Add Installer.Step 3 −Right click on the ProjectInstaller.cs [Design] and select the view code.using System; using ... Read More

How to flatten a list using LINQ C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:33:38

5K+ Views

Flattening a list means converting a List to List. For example, let us consider a List which needs to be converted to List.The SelectMany in LINQ is used to project each element of a sequence to an IEnumerable and then flatten the resulting sequences into one sequence. That means the ... Read More

How can we provide an alias name for an action method in Asp .Net MVC C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:30:51

2K+ Views

ActionName attribute is an action selector which is used for a different name of the action method. We use ActionName attribute when we want that action method to be called with a different name instead of the actual name of the method.[ActionName("AliasName")]ControllerExampleusing System.Collections.Generic; using System.Web.Mvc; namespace DemoMvcApplication.Controllers{    public class ... Read More

What are some of the fastest way to read a text file line by line using C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:28:35

2K+ Views

There are several ways to read a text file line by line. Those includes StreamReader.ReadLine, File.ReadLines etc. Let us consider a text file present in our local machine having lines like below.Using StreamReader.ReadLine −C# StreamReader is used to read characters to a stream in a specified encoding. StreamReader.Read method reads ... Read More

How to return a string repeated N number of times in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:26:04

3K+ Views

Use string instance string repeatedString = new string(charToRepeat, 5) to repeat the character "!" with specified number of times.Use string.Concat(Enumerable.Repeat(charToRepeat, 5)) to repeat the character "!" with specified number of times.Use StringBuilder builder = new StringBuilder(stringToRepeat.Length * 5); to repeat the character "!" with specified number of times.Using string instanceExample Live ... Read More

How to add custom message handlers to the pipeline in Asp.Net webAPI C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:21:23

477 Views

To create a custom Server-Side HTTP Message Handler in ASP.NET Web API, we need to create a class that must be derived from the System.Net.Http.DelegatingHandler.Step 1 −Create a controller and its corresponding action methods.Exampleusing DemoWebApplication.Models; using System.Collections.Generic; using System.Linq; using System.Web.Http; namespace DemoWebApplication.Controllers{    public class StudentController : ApiController{   ... Read More

What is the usage of DelegatingHandler in Asp.Net webAPI C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 24-Sep-2020 12:17:20

3K+ Views

In a message handler, a series of message handlers are chained together. The first handler receives an HTTP request, does some processing, and gives the request to the next handler. At some point, the response is created and goes back up the chain. This pattern is called a delegating handler.Along ... Read More

Advertisements