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
Articles by Arjun Thakur
Page 10 of 75
C# Program to split parts in a Windows directory
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 MoreDifference between prefix and postfix operators in C#?
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 MoreWhat are the prerequisites for learning C#?
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 MoreInfinity or Exception in C# when divide by 0?
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 MoreC# Linq Count method
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 MoreThe "#" custom specifier in C#
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 MoreList down a list of the escape characters in C#
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 MoreHow to initialize a tuple to an empty tuple in C#?
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 MoreReplace parts of a string with C# Regex
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 MoreC# program to get the extension of a file in C#
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