Programming Articles

Page 829 of 2547

Case-insensitive Dictionary in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

A case-insensitive Dictionary in C# allows you to perform key lookups without considering the case of string keys. This means keys like "cricket", "CRICKET", and "Cricket" are treated as identical. This is particularly useful when dealing with user input or data from external sources where case consistency cannot be guaranteed. Syntax To create a case-insensitive Dictionary, use the StringComparer.OrdinalIgnoreCase parameter in the constructor − Dictionary dict = new Dictionary(StringComparer.OrdinalIgnoreCase); You can also use other string comparers − // Culture-insensitive comparison Dictionary dict1 = new Dictionary(StringComparer.InvariantCultureIgnoreCase); // Current culture ignore case Dictionary ...

Read More

C# Numeric ("N") Format Specifier

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

The numeric (N) format specifier converts a number to a string with thousands separators and decimal places. It follows the pattern -d, ddd, ddd.ddd… where the minus sign appears for negative numbers, digits are grouped with commas, and decimal places are included. Syntax Following is the syntax for using the numeric format specifier − number.ToString("N") // Default 2 decimal places number.ToString("N0") // No decimal places number.ToString("Nn") ...

Read More

C# program to check password validity

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

While creating a password, you may have seen validation requirements on websites that ensure a password is strong and secure. Common password requirements include − Minimum 8 characters and maximum 14 characters At least one lowercase letter No whitespace characters At least one uppercase letter At least one special character Let us create a complete password validation program that checks all these conditions systematically. Complete Password Validation Program using System; using System.Linq; class PasswordValidator { public static bool IsValidPassword(string passwd) { ...

Read More

C# Program to count the number of lines in a file

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

Counting the number of lines in a file is a common task in C# programming. This can be accomplished using several methods from the System.IO namespace. The most straightforward approach is to use the File.ReadAllLines() method combined with the Length property. Using File.ReadAllLines() Method The File.ReadAllLines() method reads all lines from a file into a string array, and then we can use the Length property to count the total number of lines − Example using System; using System.IO; public class Program { public static void Main() { ...

Read More

C# Linq SkipLast Method

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

The SkipLast() method in C# LINQ is used to skip a specified number of elements from the end of a sequence and return the remaining elements. This method is particularly useful when you need to exclude the last few items from a collection. Syntax Following is the syntax for the SkipLast() method − public static IEnumerable SkipLast( this IEnumerable source, int count ) Parameters source − The sequence to skip elements from. count − The number of elements to skip from the end ...

Read More

How to split a string with a string delimiter in C#?

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

String splitting in C# is a common operation used to divide a string into substrings based on specified delimiters. The Split() method provides multiple overloads to handle different types of delimiters including characters, strings, and arrays. Syntax Following are the common syntax forms for splitting strings − // Split by single character string[] result = str.Split(', '); // Split by character array char[] delimiters = {', ', ';', '|'}; string[] result = str.Split(delimiters); // Split by string delimiter string[] result = str.Split(new string[] {"||"}, StringSplitOptions.None); Using Character Delimiters The simplest way ...

Read More

Int32.CompareTo Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 295 Views

The Int32.CompareTo method in C# is used to compare the current integer instance with another integer or object and returns an indication of their relative values. This method is particularly useful for sorting operations and conditional comparisons. Syntax The Int32.CompareTo method has two overloads − public int CompareTo(int value); public int CompareTo(object value); Parameters value − An integer or object to compare with the current instance. Return Value Return Value Condition Meaning Less than zero (< 0) Current instance < ...

Read More

C# Program to Check Whether the Entered Number is an Armstrong Number or Not

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

An Armstrong number (also called a narcissistic number) is a number that equals the sum of its digits raised to the power of the number of digits. For a 3-digit number, each digit is cubed and summed. For example, 153 is an Armstrong number because − 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 Armstrong Number Check Process 153 Original Number 1³ + 5³ + 3³ Sum of Cubes ...

Read More

What is a dictionary in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

A Dictionary in C# is a generic collection that stores data in key-value pairs. It belongs to the System.Collections.Generic namespace and provides fast lookups based on unique keys. Each key in a Dictionary must be unique, while values can be duplicated. The Dictionary class implements the IDictionary interface and uses hash tables internally for efficient data retrieval. Syntax Following is the syntax for declaring a Dictionary − Dictionary dictionaryName = new Dictionary(); You can also use the interface type for declaration − IDictionary dictionaryName = new Dictionary(); Creating and ...

Read More

What is the difference between String.Copy() and String.CopyTo() methods in C#?

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

The String.Copy() and String.CopyTo() methods in C# serve different purposes for copying string data. String.Copy() creates a new string object with the same content, while String.CopyTo() copies characters from a string into a character array. Syntax Following is the syntax for String.Copy() method − public static string Copy(string str) Following is the syntax for String.CopyTo() method − public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) Parameters String.Copy() Parameters: str − The string to copy. String.CopyTo() Parameters: sourceIndex − The index of ...

Read More
Showing 8281–8290 of 25,466 articles
« Prev 1 827 828 829 830 831 2547 Next »
Advertisements