Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 93 of 2547
Clear a StringBuilder in C#
The Clear() method in C# is used to remove all characters from a StringBuilder object, effectively resetting it to an empty state. This method is efficient as it doesn't create a new object but simply resets the internal character buffer. Syntax Following is the syntax for the Clear() method − stringBuilder.Clear(); Return Value The Clear() method returns a reference to the same StringBuilder instance with all characters removed. This allows for method chaining. Using StringBuilder Clear() Method Example The following example demonstrates how to clear a StringBuilder and check its ...
Read MoreHow to initialize an empty DateTime in C#
In C#, there are several ways to initialize an empty or default DateTime value. The most common approach is using DateTime.MinValue, which represents the minimum possible date and time value in the .NET framework. Syntax Following are the different ways to initialize an empty DateTime − DateTime dt1 = DateTime.MinValue; DateTime dt2 = new DateTime(); DateTime dt3 = default(DateTime); Using DateTime.MinValue The DateTime.MinValue property returns the minimum possible DateTime value, which is January 1, 0001 at 12:00:00 AM − using System; public class Demo { public static ...
Read MoreUInt16.ToString Method in C# with Examples
The UInt16.ToString() method in C# is used to convert the numeric value of the current UInt16 instance to its equivalent string representation. The UInt16 data type represents a 16-bit unsigned integer with a range from 0 to 65, 535. This method has multiple overloads that allow you to format the string representation using different format specifiers, culture-specific formatting, and format providers. Syntax Following is the syntax for the basic ToString() method − public override string ToString() Following is the syntax for ToString() with format specifier − public string ToString(string format) ...
Read MoreHow to find the first character of a string in C#?
To get the first character of a string in C#, you can use several approaches. The most common methods are using string indexing, the Substring() method, or the First() LINQ method. Syntax Following are the different syntaxes to get the first character − char firstChar = str[0]; string firstChar = str.Substring(0, 1); char firstChar = str.First(); Using String Indexing The simplest way to get the first character is using string indexing with [0]. This returns a char type − using System; public class Demo ...
Read MoreAccess a character in C# StringBuilder
A StringBuilder in C# allows you to access individual characters using the indexer syntax, similar to accessing elements in an array. The indexer provides both read and write access to characters at specific positions within the StringBuilder. Syntax Following is the syntax for accessing a character in StringBuilder − char character = stringBuilder[index]; Following is the syntax for modifying a character in StringBuilder − stringBuilder[index] = 'newCharacter'; Parameters index − The zero-based position of the character to access or modify. Return Value Returns the character ...
Read MoreC# General Date Short Time ("g") Format Specifier
The General Date Short Time ("g") format specifier in C# is a standard DateTime format that combines the short date pattern ("d") and short time pattern ("t"), separated by a space. This format provides a compact representation of both date and time information. Syntax Following is the syntax for using the "g" format specifier − dateTime.ToString("g") dateTime.ToString("g", CultureInfo) The format pattern varies based on the current culture or specified culture. It typically displays − Short date − MM/dd/yyyy or dd/MM/yyyy depending on culture Short time − HH:mm or h:mm tt (12-hour with ...
Read MoreWhat is the Item property of Hashtable class in C#?
The Item property of the Hashtable class in C# gets or sets the value associated with the specified key. This property uses the indexer syntax [key] and allows you to both retrieve existing values and add new key-value pairs to the hashtable. When a key does not exist in the hashtable, you can use the Item property to add it along with its value. This makes it convenient for both accessing and modifying hashtable contents. Syntax Following is the syntax for using the Item property − // Getting a value object value = hashtable[key]; ...
Read MoreDateTime.CompareTo() Method in C#
The DateTime.CompareTo() method in C# is used to compare the value of this instance to a specified DateTime value. It returns an integer indicating the chronological relationship between two DateTime objects. Syntax Following is the syntax − public int CompareTo(DateTime value); Parameters value − The DateTime object to compare with the current instance. Return Value It returns an integer value − < 0 − If this instance is earlier than the specified value 0 − If this instance is the same as the specified value > 0 − If ...
Read MoreMathF.Atanh() Method in C# with Examples
The MathF.Atanh() method in C# returns the hyperbolic arc-tangent of a single-precision floating-point value. The hyperbolic arc-tangent is the inverse of the hyperbolic tangent function and is defined only for values in the range (-1, 1). For values outside this range, the method returns NaN (Not a Number). The method is useful in mathematical calculations involving hyperbolic functions and inverse transformations. Syntax Following is the syntax − public static float Atanh(float val); Parameters val − A single-precision floating-point number representing the hyperbolic tangent whose inverse is to be found. Must ...
Read MoreC# Numeric Promotion
Numeric promotion in C# is the automatic conversion of smaller numeric types to larger types during arithmetic operations. This ensures that operations between different numeric types can be performed without data loss, following C#'s type promotion rules. When performing arithmetic operations, C# automatically promotes operands to a common type that can safely hold the result. For example, when multiplying a short and ushort, both are promoted to int before the operation. How Numeric Promotion Works The C# compiler follows a specific hierarchy when promoting numeric types during arithmetic operations − Numeric Promotion ...
Read More