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 712 of 2547
Check if the specified string is in the StringCollection in C#
To check if a specified string exists in a StringCollection, you use the Contains() method. The StringCollection class is part of the System.Collections.Specialized namespace and provides a collection specifically designed for storing strings. Syntax Following is the syntax for checking if a string exists in StringCollection − bool result = stringCollection.Contains(string value); Parameters value − The string to search for in the StringCollection. Return Value The Contains()
Read MoreOnly return fields which appear a certain number of times using MySQL DISTINCT?
To return fields appearing a certain number of times using MySQL DISTINCT, you combine GROUP BY, HAVING, and COUNT() functions. The DISTINCT keyword ensures unique groupings, while HAVING filters groups based on their count. Syntax Following is the syntax for returning fields that appear a specific number of times − SELECT DISTINCT columnName, COUNT(columnName) FROM tableName WHERE columnName LIKE 'pattern%' GROUP BY columnName HAVING COUNT(*) > threshold ORDER BY columnName; Key Components DISTINCT − Ensures unique groupings of the column values COUNT() − Counts occurrences of each grouped value GROUP BY − ...
Read MoreCount the total number of elements in the List in C#?
To count the total number of elements in a List in C#, you use the Count property. This property returns an integer value representing the current number of elements stored in the list. Syntax Following is the syntax for using the Count property − List list = new List(); int count = list.Count; Return Value The Count property returns an int value representing the number of elements currently in the list. It returns 0 for an empty list. Using Count Property with List Operations Example using System; using System.Collections.Generic; ...
Read MoreCheck if the StringCollection is read-only in C#
The StringCollection class in C# represents a collection of strings and provides an IsReadOnly property to check if the collection is read-only. A read-only collection cannot be modified after creation, meaning you cannot add, remove, or modify elements. By default, a StringCollection created using the parameterless constructor is not read-only, allowing modifications like adding or removing strings. Syntax Following is the syntax for checking if a StringCollection is read-only − bool isReadOnly = stringCollection.IsReadOnly; Return Value The IsReadOnly property returns a bool value − true − The StringCollection is read-only ...
Read MoreRemove the first occurrence from the StringCollection in C#
The StringCollection class in C# provides the Remove() method to remove the first occurrence of a specified string from the collection. This method is useful when you need to eliminate duplicate values or specific elements from your string collection. Syntax Following is the syntax for removing the first occurrence from a StringCollection − stringCollection.Remove(string value); Parameters value − The string to remove from the StringCollection. The method removes only the first occurrence if multiple instances exist. Return Value The Remove() does not return a value. It modifies ...
Read MoreGet the number of key/values pairs contained in OrderedDictionary in C#
The OrderedDictionary class in C# provides a Count property to get the number of key-value pairs it contains. This property returns an integer value representing the total number of elements in the collection. OrderedDictionary is part of the System.Collections.Specialized namespace and maintains the insertion order of elements while allowing access by both key and index. Syntax Following is the syntax for accessing the Count property − int count = orderedDictionary.Count; Using Count Property with OrderedDictionary Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { ...
Read MoreHow to return the index of first unique character without inbuilt functions using C#?
Finding the index of the first unique character in a string is a common programming problem. The approach involves using a frequency array to count character occurrences, then traversing the string again to find the first character with a count of 1. The algorithm uses an array of size 256 to accommodate all ASCII characters. First, we count the frequency of each character, then we find the first character that appears exactly once. Algorithm Steps The solution follows these steps − Create an integer array of size 256 to store character frequencies ...
Read MoreRemoving the specified key entry from HybridDictionary in C#
The HybridDictionary class in C# provides the Remove() method to remove a specified key-value pair from the collection. This method takes the key as a parameter and removes the corresponding entry if it exists. Syntax Following is the syntax for removing a key entry from HybridDictionary − public void Remove(object key); Parameters key − The key of the element to remove from the HybridDictionary. How It Works The Remove()
Read MoreHow to get Fourth Element of the Tuple in C#?
To get the fourth element of a Tuple in C#, you use the Item4 property. This property provides direct access to the fourth item stored in the tuple, regardless of the tuple's total size. Syntax Following is the syntax for accessing the fourth element of a tuple − var fourthElement = tuple.Item4; The Item4 property returns the value stored at the fourth position in the tuple. Using Item4 with Different Tuple Types Example with 7-Tuple using System; public class Demo { public static void Main(String[] ...
Read MoreCreate a Queue from another collection in C#?
Creating a Queue from another collection in C# can be accomplished using the Queue constructor that accepts an IEnumerable parameter. This allows you to initialize a new Queue with elements from arrays, lists, other queues, or any collection that implements IEnumerable. Syntax Following is the syntax to create a Queue from another collection − Queue newQueue = new Queue(sourceCollection); Where sourceCollection can be any collection implementing IEnumerable such as arrays, lists, or other queues. Using Queue Constructor with Array Example using System; using System.Collections.Generic; public class Demo { ...
Read More