Programming Articles

Page 58 of 2547

Capacity of a List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 374 Views

The Capacity property of a List in C# represents the total number of elements the internal array can hold before needing to be resized. This is different from the Count property, which represents the actual number of elements currently stored in the list. Understanding capacity is important for performance optimization, as the list automatically doubles its capacity when more space is needed, which involves allocating a new array and copying existing elements. Syntax Following is the syntax to get the capacity of a list − int capacity = listName.Capacity; You can also set ...

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

Convert the value of the current DateTime object to UTC in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

To convert the value of the current DateTime object to Coordinated Universal Time (UTC), C# provides the ToUniversalTime() method. This method converts a local time or unspecified DateTime to its equivalent UTC representation. Syntax Following is the syntax for the ToUniversalTime() method − DateTime utcDateTime = localDateTime.ToUniversalTime(); Return Value The ToUniversalTime() method returns a new DateTime object that represents the UTC equivalent of the original DateTime. If the original DateTime's Kind property is DateTimeKind.Utc, it returns the same value unchanged. Local Time to UTC Conversion ...

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

Get the hash code for the current Decimal instance in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 193 Views

The GetHashCode() method in C# returns a 32-bit signed integer hash code for the current Decimal instance. This hash code is used internally by collections like HashSet and Dictionary to efficiently store and retrieve decimal values. Hash codes are essential for the proper functioning of hash-based collections, as they provide a quick way to categorize and locate objects. Two Decimal instances that are equal will always return the same hash code, but different decimal values may occasionally produce the same hash code (hash collision). Syntax Following is the syntax for getting the hash code of a Decimal ...

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

C# String Properties

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 917 Views

The String class in C# provides essential properties that allow you to access and examine string data. The two primary properties are Chars for accessing individual characters and Length for determining the string size. String Properties Following are the key properties of the String class in C# − Property Description Chars Gets the Char object at a specified position in the current String object using indexer syntax. Length Gets the number of characters in the current String object. Syntax Following is the syntax ...

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

Difference Between C# and C++

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 638 Views

C# and C++ are both powerful programming languages, but they serve different purposes and have distinct characteristics. Understanding their differences helps developers choose the right language for their projects. What is C#? C# is a general-purpose object-oriented programming language developed by Anders Hejlsberg and his team at Microsoft. It is pronounced as 'C sharp' and is considered a pure object-oriented programming language that runs on the .NET framework. Key characteristics of C# include − Automatic memory management through garbage collection Platform-specific (primarily Windows, though .NET Core enables cross-platform development) No ...

Read More
Showing 571–580 of 25,467 articles
« Prev 1 56 57 58 59 60 2547 Next »
Advertisements