Server Side Programming Articles

Page 817 of 2109

Manipulate decimals with numeric operators in C#

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

The decimal data type in C# provides precise arithmetic operations for financial and monetary calculations. You can manipulate decimals using standard numeric operators such as +, -, *, /, and %. Decimal literals in C# must be suffixed with M or m to distinguish them from double values. This ensures precision is maintained during calculations. Syntax Following is the syntax for declaring decimal variables − decimal variableName = value M; Following is the syntax for basic arithmetic operations with decimals − decimal result = decimal1 + decimal2; // Addition decimal ...

Read More

C# Program to display temporary file names

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 305 Views

The Path.GetTempPath() method in C# retrieves the path of the system's temporary folder where temporary files are stored. This method is useful when your application needs to create temporary files or work with the system's designated temporary directory. Syntax Following is the syntax for using Path.GetTempPath() method − string tempPath = Path.GetTempPath(); Return Value The method returns a string representing the path to the system's temporary directory. On Windows, this is typically the path specified by the TEMP or TMP environment variables. On Unix-like systems, it's usually /tmp/. Using GetTempPath() to Display ...

Read More

C# Program to generate random lowercase letter

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

In C#, you can generate a random lowercase letter using the Random class and ASCII character conversion. This technique generates a random number between 0 and 25, then converts it to a corresponding lowercase letter from 'a' to 'z'. Syntax Following is the syntax for generating a random lowercase letter − Random random = new Random(); int randomIndex = random.Next(0, 26); char randomLetter = (char)('a' + randomIndex); How It Works The process involves three key steps: Generate random number: random.Next(0, 26) produces a number from 0 to 25 ...

Read More

C# Program to match all the digits in a string

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

To match all digits in a string, we can use regular expressions (Regex) in C#. Regular expressions provide a powerful way to search for patterns in text, including numeric values. The System.Text.RegularExpressions namespace contains the Regex class that allows us to define patterns and find matches within strings. Syntax Following is the syntax for matching digits using Regex − MatchCollection matches = Regex.Matches(inputString, @"\d+"); The regular expression pattern \d+ breaks down as follows − \d − matches any single digit (0-9) + − matches one or more consecutive occurrences ...

Read More

Replace parts of a string with C# Regex

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

Regular expressions (Regex) in C# provide powerful pattern matching and string replacement capabilities. The Regex.Replace() method allows you to replace parts of a string that match a specified pattern with a replacement string. Syntax Following is the syntax for using Regex.Replace() method − Regex.Replace(input, pattern, replacement); Parameters input − The string to search for a match pattern − The regular expression pattern to match replacement − The replacement string Return Value Returns a new string where all matches of the pattern are replaced with the replacement string. If no ...

Read More

C# program to get the extension of a file in C#

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

The Path.GetExtension() method in C# is used to extract the file extension from a file path. This method is part of the System.IO namespace and returns the extension portion of the path string, including the period (.). Syntax Following is the syntax for using Path.GetExtension() method − public static string GetExtension(string path) Parameters path: A string containing the file path from which to get the extension. Return Value The method returns a string containing the extension of the specified path (including the period), or an empty string if the ...

Read More

C# program to get the file name in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 753 Views

In C#, you can extract the file name from a full path using the Path.GetFileName() method from the System.IO namespace. This method returns only the file name and extension, without the directory path. Syntax Following is the syntax for using Path.GetFileName() method − string fileName = Path.GetFileName(filePath); Parameters filePath − A string containing the full path to the file. Return Value The method returns a string containing the file name and extension. If the path ends with a directory separator, it returns an empty string. Using ...

Read More

Environment.NewLine in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

The Environment.NewLine property in C# provides a platform-independent way to add line breaks in strings. It automatically returns the appropriate newline character sequence for the current operating system − \r on Windows and on Unix-based systems. Using Environment.NewLine ensures your code works correctly across different platforms without hardcoding specific line break characters. Syntax Following is the syntax for using Environment.NewLine − string result = text1 + Environment.NewLine + text2; You can also use it in string concatenation or interpolation − string result = $"Line 1{Environment.NewLine}Line 2"; Basic Usage ...

Read More

EnumerateFiles method in C#

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

The Directory.EnumerateFiles() method in C# is used to enumerate all files in a specified directory. It returns an IEnumerable collection of file paths, making it memory-efficient for large directories as it processes files lazily (one at a time) rather than loading all file paths into memory at once. Syntax Following is the basic syntax for the Directory.EnumerateFiles() method − Directory.EnumerateFiles(path) Directory.EnumerateFiles(path, searchPattern) Directory.EnumerateFiles(path, searchPattern, searchOption) Parameters path − The directory path to search for files. searchPattern − The search string to match file names (e.g., "*.*" for all files, "*.txt" for text ...

Read More

Func generic type in C#

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

The Func generic type in C# is a built-in delegate that represents a method which takes zero or more input parameters and returns a value. It provides a convenient way to store anonymous methods, lambda expressions, and regular methods that return a value. Syntax Following is the syntax for declaring a Func delegate − Func funcName; // No parameters, returns TResult Func funcName; ...

Read More
Showing 8161–8170 of 21,090 articles
« Prev 1 815 816 817 818 819 2109 Next »
Advertisements