Csharp Articles

Page 63 of 196

How to flatten a list using LINQ C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 7K+ Views

Flattening a list means converting a List to List. For example, converting a List containing multiple integer lists into a single List with all elements combined. The SelectMany operator in LINQ is used to project each element of a sequence to an IEnumerable and then flatten the resulting sequences into one sequence. It combines records from a sequence of results and converts them into a single flattened result. Flattening Process [1, 2] [3, 4] ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

A Windows Service is a long-running application that runs in the background without a user interface. In C#, you can create a Windows Service application and install it using the command prompt with the InstallUtil.exe utility. This tutorial demonstrates creating a simple Windows Service that logs messages to a text file and installing it through the command line. Creating the Windows Service Application Step 1: Create New Windows Service Project Create a new Windows Service application in Visual Studio. This provides the basic template with a Service1 class that inherits from ServiceBase. Step ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 995 Views

The || is called logical OR operator and | is called bitwise logical OR operator. The key difference between them lies in how they evaluate expressions and when they stop execution. Syntax Both operators have similar syntax − bool_exp1 || bool_exp2 // Logical OR (short-circuit) bool_exp1 | bool_exp2 // Bitwise OR (always evaluates both) Key Differences Logical OR (||) Bitwise OR (|) Short-circuit evaluation - stops if first expression is true Always evaluates both expressions More efficient for boolean operations Less ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

Every machine on a network has a unique identifier called an IP address. Just as you would address a letter to send in the mail, computers use this unique identifier to send data to specific computers on a network. In ASP.NET MVC applications, you often need to retrieve the client's IP address for logging, security, or analytics purposes. There are several methods to obtain a client's IP address in ASP.NET MVC C#. Each method has its own advantages and use cases depending on your application's architecture and hosting environment. Using HttpRequest.UserHostAddress Property The UserHostAddress property is the ...

Read More

How to run an external application through a C# application?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 5K+ Views

An external application can be run from a C# application using the Process class. A process is a program that is running on your computer. This can be anything from a small background task, such as a spell-checker or system events handler, to a full-blown application like Notepad. Each process provides the resources needed to execute a program and is started with a single thread, known as the primary thread. Processes are heavily dependent on system resources, while threads require minimal resources. The Process class is present in the System.Diagnostics namespace. Syntax Following is the basic syntax ...

Read More

What is the difference between IApplicationBuilder.Use() and IApplicationBuilder.Run() C# Asp.net Core?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 5K+ Views

We can configure middleware in the Configure method of the Startup class using IApplicationBuilder instance. The two primary methods for adding middleware are Run() and Use(), each serving different purposes in the middleware pipeline. Run() is an extension method that adds a terminal middleware to the application's request pipeline, meaning it terminates the pipeline and does not call the next middleware. Use() allows middleware to pass control to the next component in the pipeline. Syntax Following is the syntax for the Run() method − public static void Run(this IApplicationBuilder app, RequestDelegate handler) Following ...

Read More

How to enable Session in C# ASP.NET Core?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 18K+ Views

Session is a server-side storage feature in ASP.NET Core that enables you to store user data temporarily across multiple requests. Session data is stored in a dictionary on the server, with each user session identified by a unique SessionId. The SessionId is stored as a cookie on the client side and sent with every request to maintain the connection between the client and their session data. This cookie is browser-specific and cannot be shared between different browsers. While SessionId cookies persist only for the browser session, the actual session data on the server has a configurable timeout (default: 20 ...

Read More

How can we inject the service dependency into the controller C# Asp.net Core?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

ASP.NET Core uses a built-in Inversion of Control (IoC) container to inject dependencies into controllers and other services. This container, represented by the IServiceProvider implementation, supports constructor injection by default and manages application services throughout their lifecycle. To use dependency injection in controllers, you must first register your services with the IoC container in the ConfigureServices method of the Startup class or Program.cs file. Syntax Following is the syntax for registering services in the IoC container − services.AddSingleton(); services.AddScoped(); services.AddTransient(); Following is the syntax for constructor injection in a controller − ...

Read More

What is Kestral C# Asp.net Core?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 4K+ Views

Kestrel is a cross-platform web server for ASP.NET Core. It is included by default in ASP.NET Core applications and is supported on all platforms where .NET Core runs. Kestrel serves as the primary HTTP server for ASP.NET Core applications and can be configured to work either as a standalone edge server or in combination with reverse proxy servers like IIS, Nginx, or Apache. Key Features Cross-platform: Runs on Windows, macOS, and Linux. Lightweight: Minimal overhead and high performance. HTTP/HTTPS support: Handles both HTTP and HTTPS protocols. Async/await support: Built ...

Read More

What is the role of IWebHostEnvironment interface in C# ASP.NET Core?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 6K+ Views

The IWebHostEnvironment interface provides information about the web hosting environment an ASP.NET Core application is running in. It belongs to the Microsoft.AspNetCore.Hosting namespace and is commonly used to access file paths and environment details. The IWebHostEnvironment interface needs to be injected as a dependency in controllers, services, or other components through ASP.NET Core's built-in dependency injection system. Key Properties The IWebHostEnvironment interface provides two essential properties − WebRootPath − Gets or sets the absolute path to the directory that contains web-servable application content files (typically the wwwroot folder) ContentRootPath − Gets or sets the absolute ...

Read More
Showing 621–630 of 1,951 articles
« Prev 1 61 62 63 64 65 196 Next »
Advertisements