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 94 of 2547
C# Program to change a character from a string
In C#, strings are immutable, meaning their characters cannot be changed directly. However, you can change characters in a string using the StringBuilder class, which provides a mutable sequence of characters. The StringBuilder class allows you to modify individual characters using indexer notation str[index] = newChar, where the index is zero-based. Syntax Following is the syntax for changing a character in a StringBuilder − StringBuilder stringBuilder = new StringBuilder("original"); stringBuilder[index] = 'newChar'; Using StringBuilder to Change Characters Let's say our string is − StringBuilder str = new StringBuilder(); str.Append("pre"); ...
Read MoreC# DateTime Max Value
The DateTime.MaxValue property in C# returns the maximum possible value for a DateTime object. This represents the largest date and time that can be stored in a DateTime structure, which is December 31, 9999 at 11:59:59.9999999 PM. This property is useful when you need to initialize a DateTime variable with the highest possible value, compare dates to find the maximum, or set upper bounds in date range validations. Syntax Following is the syntax for accessing the maximum DateTime value − DateTime maxValue = DateTime.MaxValue; DateTime MaxValue Example The following example demonstrates how ...
Read MoreChar.IsLetterOrDigit() Method in C#
The Char.IsLetterOrDigit() method in C# determines whether a specified Unicode character is categorized as a letter or a decimal digit. This method is useful for validating input characters, parsing strings, and filtering alphanumeric content. Syntax Following is the syntax for the Char.IsLetterOrDigit() method − public static bool IsLetterOrDigit(char ch); There is also an overloaded version that works with strings − public static bool IsLetterOrDigit(string s, int index); Parameters ch − The Unicode character to evaluate. s − A string. index − The position of the character to evaluate ...
Read MoreDecimal to Multiple-Bases Conversion with Stack
Decimal to multiple-base conversion is a common programming task where we convert a decimal number to binary, octal, hexadecimal, or any other base. Using a stack data structure makes this process efficient because stacks follow the Last-In-First-Out (LIFO) principle, which naturally reverses the remainder sequence obtained during division. How It Works The conversion algorithm repeatedly divides the decimal number by the target base and stores remainders in a stack. When we pop elements from the stack, we get the digits in the correct order for the converted number. Decimal to Binary Conversion (45 ...
Read MoreHow to find the length and rank of a jagged array in C#?
A jagged array in C# is an array of arrays where each sub-array can have different lengths. Unlike multi-dimensional arrays, jagged arrays provide flexibility in storing varying amounts of data in each row. To find the length and rank of a jagged array, you can use the Length property, GetLowerBound() and GetUpperBound() methods, and the Rank property. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[rows][]; Following are the methods and properties to find length and rank − arrayName.Length ...
Read MoreC# program to remove characters starting at a particular index in StringBuilder
The StringBuilder class in C# provides the Remove() method to delete a sequence of characters starting from a specific index position. This method is more efficient than string manipulation when performing multiple character operations. Syntax Following is the syntax for the Remove() method − StringBuilder.Remove(int startIndex, int length) Parameters startIndex − The zero-based position where removal begins. length − The number of characters to remove. Return Value The method returns a reference to the same StringBuilder instance after the removal operation, allowing for method chaining. ...
Read MoreC# Program to return specified number of elements from the end of an array
The TakeLast() method in C# returns a specified number of elements from the end of a sequence. It's part of the LINQ library and provides an efficient way to extract the last few elements from arrays, lists, or other enumerable collections. Syntax Following is the syntax for using TakeLast() − IEnumerable TakeLast(int count) Parameters count − The number of elements to return from the end of the sequence. Return Value Returns an IEnumerable containing the specified number of elements from the end of the source sequence. Using TakeLast() ...
Read MoreC# program to find maximum and minimum element in an array
To find the maximum and minimum elements in an array in C#, we initialize both values to the first element of the array and then compare each subsequent element. This approach ensures we correctly identify the extreme values regardless of the array's content. Algorithm The algorithm follows these steps − Initialize both max and min variables to the first array element. Iterate through the array starting from the second element (index 1). Compare each element with the current max and min values. Update max and min accordingly when a larger or smaller element is found. ...
Read MoreC# TimeSpan Min value
The TimeSpan structure in C# represents a time interval or duration. The TimeSpan.MinValue property returns the minimum possible value that a TimeSpan can represent, which is approximately -10.7 million days. This minimum value is useful when you need to initialize a TimeSpan variable to the smallest possible value or when performing comparisons to find the minimum time span in a collection. Syntax Following is the syntax to access the minimum TimeSpan value − TimeSpan.MinValue Return Value The TimeSpan.MinValue property returns a TimeSpan object representing the minimum possible time interval, which equals approximately ...
Read MoreChar.IsLower() Method in C#
The Char.IsLower() method in C# is used to determine whether a specified Unicode character is categorized as a lowercase letter. This method is part of the System.Char class and provides a convenient way to validate character case in string processing operations. Syntax Following is the syntax for the Char.IsLower() method − public static bool IsLower(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a lowercase letter; otherwise, false. Using Char.IsLower() with Uppercase Characters The following example ...
Read More