Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Nizamuddin Siddiqui
Page 21 of 196
What is ViewData in ASP .Net MVC C#?
ViewData is a dictionary-based container in ASP.NET MVC that enables data transfer from Controller to View. It stores key-value pairs where keys are strings and values are objects, making it a flexible but loosely-typed data transfer mechanism. ViewData is valid only during the current HTTP request and provides one-way communication from controller to view. Since it uses string keys and object values, it requires explicit casting when retrieving data and does not provide compile-time type checking. Syntax Following is the syntax for storing data in ViewData − ViewData["keyName"] = value; Following is the ...
Read MoreWhat is the usage of DelegatingHandler in Asp.Net webAPI C#?
In ASP.NET Web API, a DelegatingHandler is a type of HTTP message handler that forms a chain of handlers to process HTTP requests and responses. Each handler in the chain can perform operations on the request before passing it to the next handler, and then process the response when it comes back up the chain. The DelegatingHandler class allows you to create custom server-side message handlers that can intercept, modify, or handle HTTP requests and responses globally across your Web API application. This is useful for implementing cross-cutting concerns like logging, authentication, caching, or request validation. Syntax ...
Read MoreHow to add custom message handlers to the pipeline in Asp.Net webAPI C#?
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. Message handlers allow you to intercept HTTP requests and responses, enabling cross-cutting concerns like logging, authentication, caching, or request modification. How Message Handlers Work Message handlers form a pipeline where each handler can process the request before passing it to the next handler, and process the response on its way back. This provides a powerful mechanism for implementing middleware-like functionality in Web API. Message Handler Pipeline ...
Read MoreHow to return a string repeated N number of times in C#?
There are several ways to repeat a string or character N number of times in C#. This article covers three effective approaches: using the string constructor for characters, string.Concat with Enumerable.Repeat, and StringBuilder for more complex scenarios. Using String Constructor for Characters The simplest way to repeat a single character is using the string constructor that takes a character and a count − string repeatedString = new string(character, count); Example using System; namespace DemoApplication { public class Program { ...
Read MoreWhat are some of the fastest way to read a text file line by line using C#?
There are several fast and efficient ways to read a text file line by line in C#. The most commonly used methods are StreamReader.ReadLine, File.ReadLines, and File.ReadAllLines. Each method has its own advantages depending on the use case and file size. Using StreamReader.ReadLine StreamReader is the most memory-efficient approach for reading large files since it processes one line at a time without loading the entire file into memory. This method is ideal for processing very large files where memory usage is a concern. Example using System; using System.IO; using System.Text; namespace DemoApplication { ...
Read MoreHow to flatten a list using LINQ C#?
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 MoreHow to install a windows service using windows command prompt in C#?
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 MoreWhat is the difference between | and || operators in c#?
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 MoreHow can we get the client's IP address in ASP.NET MVC C#?
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 MoreHow to set a property having different datatype with a string value using reflection in C#?
Reflection in C# allows managed code to examine and manipulate its own metadata, including types, properties, and methods at runtime. This powerful feature enables you to dynamically work with objects without knowing their types at compile time. A common scenario is when you need to set a property of one data type (like double) using a string value at runtime. This can be accomplished using reflection combined with type conversion. Syntax Following is the syntax for getting property information using reflection − PropertyInfo propertyInfo = obj.GetType().GetProperty("PropertyName"); Following is the syntax for setting a ...
Read More