Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 15 of 196

How can we create a LOG filter for Logging purposes in C# ASP.NET WebAPI?

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

Action filters in C# ASP.NET Web API are used to add extra logic before or after action methods execution. The OnActionExecuting and OnActionExecuted methods allow you to inject custom logic at specific points in the request pipeline, making them perfect for logging purposes. A LOG filter helps track API method calls, execution times, and other diagnostic information. This is particularly useful for debugging, performance monitoring, and audit trails in production applications. Syntax Following is the syntax for creating a custom action filter by inheriting from ActionFilterAttribute − public class LogAttribute : ActionFilterAttribute { ...

Read More

What is Shallow Copy and how it is different from Deep Copy in C#?

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

A shallow copy creates a new object but copies only the reference values from the original object. When the copied object contains reference types, both the original and copied objects point to the same memory locations for those inner objects. A deep copy creates a completely independent copy of an object, including all nested objects. Changes to one object do not affect the other since they occupy separate memory spaces. Shallow Copy vs Deep Copy Shallow Copy ...

Read More

How to make use of both Take and Skip operator together in LINQ C#?

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

The Take and Skip operators in LINQ C# are powerful tools for data manipulation. The Skip operator skips over a specified number of elements from the beginning of a sequence, while the Take operator returns a specified number of elements from the beginning of a sequence. When used together, Skip and Take enable you to implement pagination and extract specific ranges of data from collections. This combination is particularly useful for scenarios like displaying search results in pages or processing data in chunks. Syntax Following is the syntax for using Skip operator − var result ...

Read More

How to create an array with non-default repeated values in C#?

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

We can create an array with non-default repeated values using Enumerable.Repeat(). This method creates a sequence that contains one repeated value a specified number of times. It requires the System.Linq namespace to be included. Syntax Following is the syntax for using Enumerable.Repeat() − IEnumerable Enumerable.Repeat(T element, int count) Parameters element − The value to be repeated in the sequence. count − The number of times to repeat the value in the generated sequence. Return Value Returns an IEnumerable that contains a repeated value. To convert ...

Read More

How to force garbage collection in C#?

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

The garbage collector in C# automatically manages memory by removing unused objects. However, you can force garbage collection to run immediately using the GC.Collect() method, though this is generally not recommended due to performance implications. Forcing garbage collection should only be used in specific scenarios where you know large amounts of memory have been freed and want to clean up immediately, such as after closing a large document or completing a memory-intensive operation. Syntax Following is the syntax for forcing garbage collection − GC.Collect(); To collect specific generations − GC.Collect(int generation); ...

Read More

How to get the Unix timestamp in C#

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

A Unix timestamp is a system for describing time as the number of seconds that have elapsed since January 1, 1970, at 00:00:00 UTC. This epoch time is widely used across different operating systems and programming languages for consistent time representation. Unix timestamps are particularly useful for storing dates in databases, comparing times across different time zones, and working with APIs that expect epoch time values. What is Unix Timestamp? The Unix timestamp represents time as a single integer value − the count of seconds since the Unix epoch (January 1, 1970, UTC). This makes it timezone-independent ...

Read More

What is if/then directives for debug vs release in C#?

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

In C#, conditional compilation directives like #if DEBUG allow you to include or exclude code based on the build configuration. Visual Studio provides two main build configurations: Debug mode for development and debugging, and Release mode for final production builds. The #if DEBUG directive enables code to execute only when compiled in Debug mode. In Release mode, this code is completely excluded from compilation, making it useful for debugging statements, logging, and development-only features. Syntax Following is the basic syntax for conditional compilation directives − #if DEBUG // Code executed only ...

Read More

What are built-in message handlers in Asp.Net webAPI C#?

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

A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class and provide us the opportunity to process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher. Message handlers are executed much earlier in the request processing pipeline, making them ideal for implementing cross-cutting concerns in Web API. They form a chain of classes that process HTTP requests and responses through a pipeline. ASP.NET Web API Message Handler Pipeline ...

Read More

How to sort a list of complex types using Comparison delegate in C#?

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

Sorting a list of complex types in C# can be achieved using the Comparison delegate with the Sort() method. The List.Sort() method has an overload that accepts a Comparison delegate, allowing you to define custom sorting logic for complex objects. The Comparison delegate represents a method that compares two objects of the same type and returns an integer indicating their relative order. Syntax Following is the syntax for the Sort() method using a Comparison delegate − public void Sort(Comparison comparison) The comparison delegate signature is − public delegate int Comparison(T x, ...

Read More

What is the difference between Monitor and Lock in C#?

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

Both Monitor and lock provide thread synchronization mechanisms in C#, but they serve different purposes. The lock statement is a simplified syntax that internally uses Monitor.Enter and Monitor.Exit with proper exception handling. Monitor offers more advanced features for complex threading scenarios. Syntax Following is the syntax for using lock statement − lock (lockObject) { // critical section code } Following is the syntax for using Monitor class − Monitor.Enter(lockObject); try { // critical section code } finally { Monitor.Exit(lockObject); } ...

Read More
Showing 141–150 of 1,958 articles
« Prev 1 13 14 15 16 17 196 Next »
Advertisements