Server Side Programming Articles

Page 819 of 2109

C# Program to remove whitespaces in a string

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 9K+ Views

In C#, there are several ways to remove whitespaces from a string. You can remove all spaces, only leading and trailing spaces, or all types of whitespace characters including tabs and newlines. Using String.Replace() Method The Replace()

Read More

How to get complete drive information using C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 301 Views

Drive information of an Operating System includes key details about storage drives such as drive name, volume label, free space, total size, drive format, and drive type. In C#, you can retrieve this information using the DriveInfo class from the System.IO namespace. Syntax Following is the syntax for creating a DriveInfo object and accessing its properties − DriveInfo driveInfo = new DriveInfo("DriveLetter"); string name = driveInfo.Name; long freeSpace = driveInfo.AvailableFreeSpace; DriveType type = driveInfo.DriveType; DriveInfo Properties Property Description Name Gets the drive name (e.g., "C:") ...

Read More

Represent Int32 as a Binary String in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 10K+ Views

To represent an Int32 as a binary string in C#, use the Convert.ToString() method with base 2 as the second parameter. This method converts the integer's binary representation into a readable string format. Int32 represents a 32-bit signed integer that can hold values from -2, 147, 483, 648 to 2, 147, 483, 647. Syntax Following is the syntax for converting an integer to binary string − Convert.ToString(value, 2) Parameters value − The integer value to convert to binary representation 2 − The base for binary number system ...

Read More

Convert a ValueTuple to a Tuple in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 596 Views

In C#, you can easily convert a ValueTuple to a Tuple using the ToTuple() method. ValueTuples are value types introduced in C# 7.0, while Tuples are reference types that have been available since earlier versions of C#. Note − For .NET Framework projects, you may need to add the System.ValueTuple NuGet package to use ValueTuple features. Syntax Following is the syntax for converting a ValueTuple to a Tuple using the ToTuple() method − var valueTuple = (value1, value2, value3); Tuple tuple = valueTuple.ToTuple(); Converting ValueTuple to Tuple Example using System; ...

Read More

C# Round-trip ("R") Format Specifier

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

The round-trip ("R") format specifier in C# ensures that a numeric value converted to a string can be parsed back into the same exact numeric value without any precision loss. This format specifier is supported for Single, Double, and BigInteger types. The "R" specifier is particularly useful when you need to serialize floating-point numbers to strings and then deserialize them back while maintaining perfect accuracy. Syntax Following is the syntax for using the round-trip format specifier − value.ToString("R") value.ToString("R", CultureInfo.InvariantCulture) How It Works The round-trip format specifier automatically determines the minimum number ...

Read More

C# Hexadecimal ("X") Format Specifier

Samual Sam
Samual Sam
Updated on 17-Mar-2026 9K+ Views

The hexadecimal ("X") format specifier is used to convert a number to a string of hexadecimal digits. The case of the format specifier determines whether hexadecimal digits greater than 9 are displayed in uppercase or lowercase. Use "X" for uppercase hexadecimal letters (A, B, C, D, E, F) and "x" for lowercase hexadecimal letters (a, b, c, d, e, f). Syntax Following is the syntax for using the hexadecimal format specifier − number.ToString("X") // uppercase number.ToString("x") // lowercase number.ToString("X4") // uppercase with minimum 4 ...

Read More

How to generate a string randomly using C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 729 Views

Generating random strings in C# is useful for creating passwords, test data, or unique identifiers. There are several approaches to generate random strings, from simple character-based methods to more advanced techniques using predefined character sets. Syntax Following is the basic syntax for generating random strings using Random class − Random random = new Random(); char randomChar = (char)random.Next(startValue, endValue); Following is the syntax using a character array − char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char randomChar = chars[random.Next(chars.Length)]; Using ASCII Values for Random String Generation This method generates random characters by ...

Read More

C# program to create a ValueType with names

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 199 Views

ValueTuples in C# allow you to create lightweight data structures with named fields. Introduced in C# 7, ValueTuples provide a convenient way to group multiple values together without creating a separate class or struct. Note − For .NET Framework projects, you may need to add the System.ValueTuple NuGet package to use ValueTuples. Installing System.ValueTuple Package To add the System.ValueTuple package to your project − Go to your project Right click on the project in the Solution Explorer Select "Manage NuGet Packages" Click the Browse tab and search for "System.ValueTuple" Install the System.ValueTuple package ...

Read More

Why is a Dictionary preferred over a Hashtable in C#?

George John
George John
Updated on 17-Mar-2026 329 Views

In C#, Dictionary is generally preferred over Hashtable due to its better performance, type safety, and modern design. Both are key-value collections, but Dictionary provides significant advantages for most applications. A Hashtable is a non-generic collection that stores key-value pairs as object types, requiring boxing and unboxing operations. A Dictionary is a generic collection from the System.Collections.Generic namespace that provides compile-time type safety and better performance. Key Differences Feature Hashtable Dictionary Type Safety No compile-time type checking Strong type checking at compile-time Performance Slower due to boxing/unboxing Faster, ...

Read More

Where to use #region directive in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 5K+ Views

The #region directive in C# is a preprocessor directive that allows you to specify a block of code that can be collapsed or expanded in code editors like Visual Studio. This feature improves code organization and readability by grouping related code sections together. The #region directive must always be paired with a corresponding #endregion directive to mark the end of the collapsible block. Syntax Following is the syntax for using the #region directive − #region Region Name or Description // Code block that can be collapsed #endregion Basic Usage of #region Example ...

Read More
Showing 8181–8190 of 21,090 articles
« Prev 1 817 818 819 820 821 2109 Next »
Advertisements