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 715 of 2547
Remove a range of elements from the List in C#
The RemoveRange() method in C# allows you to remove multiple elements from a List at once by specifying a starting index and the number of elements to remove. This is more efficient than removing elements one by one. Syntax Following is the syntax for the RemoveRange() method − public void RemoveRange(int index, int count) Parameters index − The zero-based starting index of the range of elements to remove. count − The number of elements to remove starting from the specified index. RemoveRange(1, 3) Example ...
Read MoreHow to print number of islands in a given matrix using C#?
An island in a matrix is a group of connected cells containing '1' (representing land) that are surrounded by '0' (representing water). Two cells are considered connected if they are adjacent horizontally or vertically. This problem uses Depth-First Search (DFS) to traverse and mark all connected land cells as visited. The algorithm performs a linear scan of the 2D grid. When it finds a '1' that hasn't been visited, it triggers a DFS to explore the entire connected island and marks all cells in that island as visited. Each DFS call represents one complete island. Algorithm Steps ...
Read MoreChar.IsLetter() Method in C#
The Char.IsLetter() method in C# is used to determine whether a specified Unicode character is categorized as a Unicode letter. This method returns true if the character is a letter (uppercase or lowercase), and false otherwise. This method is particularly useful for input validation, text processing, and character classification in applications where you need to distinguish letters from numbers, symbols, or other character types. Syntax Following is the syntax − public static bool IsLetter(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns ...
Read MoreRemoving first occurrence of object from Collection in C#
The Collection.Remove() method in C# removes the first occurrence of a specified object from the collection. This method searches through the collection sequentially and removes only the first matching element it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for the Remove() method − public bool Remove(T item) Parameters item: The object to remove from the collection. The value can be null for reference types. Return Value The method returns a bool value − true: If the item was successfully found and removed false: ...
Read MoreC# Program to Read a String and Find the Sum of all Digits
C# is a popular object-oriented programming language used to develop Windows applications, web applications, and games. In this article, we will discuss how to write a C# program to read a string and find the sum of all digits present in the string. Approach To find the sum of digits in a string, we need to iterate through each character, check if it's a digit using char.IsDigit(), and convert it to an integer to add to our running sum. Using char.IsDigit() Method The char.IsDigit() method determines whether a character represents a decimal digit. Here's the complete ...
Read MoreRemoving first occurrence of specified value from LinkedList in C#
The LinkedList.Remove(T) method in C# removes the first occurrence of the specified value from a LinkedList. This method searches the LinkedList from the beginning and removes only the first matching node it encounters, leaving any subsequent duplicates unchanged. Syntax Following is the syntax for removing the first occurrence of a specified value − public bool Remove(T value) Parameters value: The value to remove from the LinkedList. Return Value Returns true if the element is successfully found and removed; otherwise, false. This method also returns false if the value was ...
Read MoreC# Program to Check if Value exists in Hashtable
The hashtable is an organized collection of key-value pairs wherein the keys are arranged as per the hash code of the key calculated using the hash function. While the keys should be non-null and unique in a hashtable, the values can be null and duplicate. The elements in the hashtable are accessed using the keys. In C#, the class Hashtable represents the hashtable collection. This class provides various properties and methods using which we can perform operations and access data in the hashtable. In this article, we will see how we can determine if a particular value is ...
Read MoreHow to find all the permutation of the string by backtracking using C#?
String permutation using backtracking is a classic algorithm that generates all possible arrangements of characters in a string. The approach works by fixing one character at a time and recursively finding permutations of the remaining characters, then backtracking to explore other possibilities. The core idea is to swap characters systematically − fix the first position with each character, find permutations of the rest, then backtrack by undoing the swap to try the next possibility. Backtracking Process for "ABC" ABC ...
Read MoreHow to change the Foreground Color of Text in C# Console?
To change the foreground color of text in C# console applications, use the Console.ForegroundColor property. This property accepts a ConsoleColor enumeration value and affects all subsequent text output until changed again. Syntax Following is the syntax for setting console foreground color − Console.ForegroundColor = ConsoleColor.ColorName; To reset to default colors, use − Console.ResetColor(); Available Colors The ConsoleColor enumeration provides the following color options − Color Name Description Black, DarkBlue, DarkGreen, DarkCyan Dark color variants DarkRed, DarkMagenta, DarkYellow, Gray Medium ...
Read MoreGet the number of key/value pairs contained in ListDictionary in C#
To get the number of key/value pairs contained in ListDictionary, you use the Count property. The ListDictionary class in C# is part of the System.Collections.Specialized namespace and is optimized for small collections with typically fewer than 10 elements. The Count property returns an integer representing the total number of key/value pairs currently stored in the ListDictionary. Syntax Following is the syntax for getting the count of key/value pairs in ListDictionary − ListDictionary listDict = new ListDictionary(); int count = listDict.Count; Using Count Property Example using System; using System.Collections; using System.Collections.Specialized; ...
Read More