Arjun Thakur

Arjun Thakur

749 Articles Published

Articles by Arjun Thakur

Page 10 of 75

C# Program to split parts in a Windows directory

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

A Windows directory path consists of multiple parts separated by backslashes (\). In C#, you can split a directory path into its individual components using the Split() method with the backslash character as the delimiter. This technique is useful for extracting specific parts of a path, validating directory structures, or processing file paths programmatically. Syntax Following is the syntax for splitting a Windows directory path − string[] parts = directoryPath.Split(''); You can also use the verbatim string literal to define the path − string path = @"C:\Users\Documents\MyFile.txt"; Using Split() ...

Read More

Difference between prefix and postfix operators in C#?

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

The prefix and postfix operators in C# are increment (++) and decrement (--) operators that behave differently based on their position relative to the variable. The key difference lies in when the increment or decrement occurs and what value is returned. Syntax Following is the syntax for prefix operators − ++variable; // prefix increment --variable; // prefix decrement Following is the syntax for postfix operators − variable++; // postfix increment variable--; // postfix decrement Prefix Operators The prefix operator increments or decrements the variable first, ...

Read More

What are the prerequisites for learning C#?

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

To start learning C#, you should have basic computer knowledge and familiarity with fundamental programming concepts. While prior experience with C or C++ is helpful, it is not mandatory − C# is beginner-friendly and can be your first programming language. Prerequisites Here are the essential prerequisites for learning C# − Basic Computer Skills: Understanding how to navigate files, folders, and install software. Programming Fundamentals: Basic knowledge of variables, loops, and conditional statements (helpful but not required). Mathematical Logic: Understanding of basic mathematical operations and logical thinking. Object-Oriented Concepts: Familiarity ...

Read More

Infinity or Exception in C# when divide by 0?

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

When dividing by zero in C#, the behavior depends on the data type being used. Integer division by zero throws a DivideByZeroException, while floating-point division by zero returns Infinity or NaN (Not a Number) without throwing an exception. Syntax Following is the basic division syntax that can result in divide-by-zero scenarios − result = dividend / divisor; Exception handling syntax for integer division − try { result = dividend / divisor; } catch (DivideByZeroException ex) { // handle exception } Integer Division ...

Read More

C# Linq Count method

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

The Count method in LINQ returns the number of elements in a sequence. It is one of the most commonly used LINQ methods for determining collection size and can be used with arrays, lists, and any IEnumerable collection. Syntax Following is the syntax for the basic Count method − int count = collection.Count(); Following is the syntax for Count with a predicate condition − int count = collection.Count(predicate); Using Count() on Arrays and Collections The Count method can be applied to any collection that implements IEnumerable. Here's how to ...

Read More

The "#" custom specifier in C#

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

The # custom format specifier in C# serves as a digit placeholder symbol in numeric formatting. It displays a digit only if one exists at that position, making it useful for creating flexible number formats that suppress unnecessary leading and trailing zeros. Syntax Following is the syntax for using the # format specifier − number.ToString("#formatPattern") String.Format("{0:#formatPattern}", number) How It Works When formatting a number, the # symbol represents an optional digit position. If the value has a digit at that position, it displays the digit. If not, nothing is displayed for that position. ...

Read More

List down a list of the escape characters in C#

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

Escape characters in C# are special character sequences that begin with a backslash (\) and represent characters that cannot be directly typed or displayed. They are commonly used in strings, regular expressions, and character literals to represent control characters, special symbols, and Unicode characters. Common Escape Characters The most frequently used escape characters include for new lines, \t for tabs, and " for quotes within strings. Example using System; class Program { static void Main() { Console.WriteLine("Hello\tWorld"); ...

Read More

How to initialize a tuple to an empty tuple in C#?

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

To initialize a tuple to an empty tuple in C#, you can declare a tuple variable without assigning it a value, or assign it to null. C# provides multiple ways to work with empty or uninitialized tuples depending on your specific requirements. Syntax Following are the different ways to declare an empty tuple − // Declare without initialization (default to null) Tuple myTuple; // Initialize to null explicitly Tuple myTuple = null; // Create tuple with null/default values Tuple myTuple = new Tuple(0, null); Using Uninitialized Tuple Declaration When you declare ...

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
Showing 91–100 of 749 articles
« Prev 1 8 9 10 11 12 75 Next »
Advertisements