Programming Articles

Page 41 of 2547

What is connection pooling in C# and how to achieve it?

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

Connection pooling in C# is a technique that improves database application performance by reusing database connections rather than creating new ones for each request. When a connection is closed, it's returned to a pool for future use instead of being destroyed. The .NET Framework automatically manages connection pooling for ADO.NET connections. When you use the using statement with database connections, it ensures proper disposal and automatic participation in connection pooling. How Connection Pooling Works Connection Pool Lifecycle Application Connection Pool ...

Read More

Uri.IsHexDigit() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 159 Views

The Uri.IsHexDigit() method in C# determines whether a specified character is a valid hexadecimal digit. This method returns true if the character is a valid hexadecimal digit (0-9, A-F, a-f), and false otherwise. This method is commonly used when working with URL encoding, parsing hexadecimal values, or validating user input that should contain only hexadecimal characters. Syntax Following is the syntax − public static bool IsHexDigit(char ch); Parameters ch − The character to validate as a hexadecimal digit. Return Value Returns true if the character is ...

Read More

Single.ToString Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 153 Views

The Single.ToString() method in C# converts a float (single-precision floating-point) value to its string representation. This method is essential for displaying numeric values as text or preparing them for output operations. Syntax Following is the syntax for the parameterless ToString() method − public override string ToString(); The method can also accept format parameters − public string ToString(string format); public string ToString(IFormatProvider provider); public string ToString(string format, IFormatProvider provider); Return Value The method returns a string representation of the float value. Special values like infinity and NaN have specific string ...

Read More

Getting the unique identifier for the current managed thread in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 246 Views

To get the unique identifier for the currently managed thread in C#, you can use the Thread.CurrentThread.ManagedThreadId property. This property returns an integer that uniquely identifies each managed thread within the application domain. The ManagedThreadId is different from the operating system thread ID and is specifically designed for managed code debugging and logging purposes. Syntax Following is the syntax for getting the managed thread ID − int threadId = Thread.CurrentThread.ManagedThreadId; For a specific thread object − Thread thread = new Thread(methodName); int threadId = thread.ManagedThreadId; Using ManagedThreadId with Regular ...

Read More

How to use strings in switch statement in C#

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

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. In C#, you can use strings directly in switch statements, making it convenient to handle text-based conditions. Syntax Following is the syntax for using strings in a switch statement − switch (stringVariable) { case "value1": // code block break; case "value2": ...

Read More

How to Delete Item from Hashtable Collection in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 583 Views

The Hashtable in C# is a collection of key-value pairs that are organized based on the hash code of the key. Items in the hashtable are accessed using a key, and the Hashtable class provides various methods to perform operations like adding, removing, and checking for the existence of specified keys. In this article, we will discuss how to delete an item from the hashtable collection using a specified key with the Remove() method. Syntax The Hashtable class provides the Remove() method to delete an item from the hashtable collection − public virtual void Remove(object ...

Read More

What is @ in front of a string in C#?

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

The @ symbol in front of a string in C# creates a verbatim string literal. This special prefix tells the compiler to treat the string exactly as written, ignoring escape sequences and preserving formatting including line breaks. In C#, a verbatim string is created using the @ symbol as a prefix before the opening quote. The compiler identifies this as a verbatim string and processes it literally. The main advantage of the @ symbol is to tell the string constructor to ignore escape characters and preserve line breaks exactly as they appear in the source code. Syntax ...

Read More

How to replace multiple spaces with a single space in C#?

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

There are several ways to replace multiple consecutive spaces with a single space in C#. This is a common task when cleaning up text data or normalizing whitespace in strings. The most effective approaches include using Regex.Replace() for pattern matching, string.Join() with Split() for splitting and rejoining, and string.Replace() for simple cases. Using Regex.Replace() The Regex.Replace() method uses regular expressions to find and replace patterns. The pattern \s+ matches one or more consecutive whitespace characters − using System; using System.Text.RegularExpressions; namespace DemoApplication { class Program { ...

Read More

How to implement Null object Pattern in C#?

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

The Null Object Pattern is a behavioral design pattern that helps eliminate null checks by providing a default object that implements the expected interface but performs no operations. Instead of returning null, you return a null object that behaves safely when methods are called on it. This pattern is particularly useful when you want to avoid NullReferenceException and make your code more readable by eliminating repetitive null checks. The null object provides a neutral behavior that represents "do nothing" or "no operation". Structure of Null Object Pattern Null Object Pattern Structure ...

Read More

How to add key/value pairs in SortedList in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 320 Views

A SortedList in C# is a collection that stores key/value pairs sorted by keys. The Add() method is the primary way to insert key/value pairs into a SortedList, automatically maintaining sorted order based on the keys. Syntax Following is the syntax for adding key/value pairs to a SortedList − SortedList sortedList = new SortedList(); sortedList.Add(key, value); Parameters key − The key of the element to add. Cannot be null and must be unique. value − The value of the element to add. Can be null. Using ...

Read More
Showing 401–410 of 25,467 articles
« Prev 1 39 40 41 42 43 2547 Next »
Advertisements