Programming Articles

Page 730 of 2547

Single.ToString Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 163 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 257 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 603 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 233 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 330 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

Convert the value of the current DateTime object to a Windows file time in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 362 Views

The DateTime.ToFileTime() method in C# converts the value of the current DateTime object to a Windows file time. A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (UTC). This method is commonly used when working with file system operations, as Windows stores file timestamps in this format internally. Syntax Following is the syntax for the ToFileTime() method − public long ToFileTime() Return Value The method returns a long value representing the Windows file time equivalent of ...

Read More

BitConverter.ToInt16() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 343 Views

The BitConverter.ToInt16() method in C# is used to convert two consecutive bytes from a byte array into a 16-bit signed integer (short). This method reads bytes in little-endian format, where the first byte represents the lower-order bits and the second byte represents the higher-order bits. Syntax Following is the syntax for the BitConverter.ToInt16() method − public static short ToInt16(byte[] value, int startIndex); Parameters value − The byte array containing the bytes to convert. startIndex − The starting position within the byte array from which to begin reading two bytes. Return ...

Read More
Showing 7291–7300 of 25,466 articles
« Prev 1 728 729 730 731 732 2547 Next »
Advertisements