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 100 of 2547
C# Queue.TrimExcess() Method with Examples
The Queue.TrimExcess() method in C# is used to set the capacity to the actual number of elements in the Queue, if that number is less than 90 percent of current capacity. This method helps optimize memory usage by reducing the internal array size when the queue has significantly fewer elements than its current capacity. Syntax public void TrimExcess(); Parameters: This method takes no parameters. Return Value: This method does not return any value (void). How It Works The TrimExcess() method only reduces capacity when the current element count is less than 90% ...
Read MoreGet the maximum value in the SortedSet in C#
The SortedSet class in C# provides the Max property to efficiently retrieve the maximum value from the collection. Since SortedSet maintains elements in sorted order, the maximum element is always the last element in the collection. Syntax Following is the syntax for getting the maximum value from a SortedSet − SortedSet sortedSet = new SortedSet(); T maxValue = sortedSet.Max; Properties Property Description Return Type Max Gets the maximum value in the SortedSet according to the comparer. T Min Gets the minimum value in the ...
Read MoreHow to find the minimum number of steps needed by knight to reach the destination using C#?
In chess, a knight moves in an L-shape − two squares in one direction and one square perpendicular to that. This article explains how to find the minimum number of steps (moves) needed for a knight to reach a destination cell on a chessboard using Breadth-First Search (BFS) algorithm in C#. The knight's movement pattern creates a shortest path problem that can be efficiently solved using BFS, as it explores all possible moves level by level, guaranteeing the minimum number of steps. Knight's Movement Pattern A knight can move to at most 8 positions from any given ...
Read MoreUri.IsBaseOf(Uri) Method in C#
The Uri.IsBaseOf() method in C# is used to determine whether the current Uri instance is a base of the specified Uri instance. This method is particularly useful when working with URL hierarchies and checking if one URI is a parent or base path of another URI. Syntax Following is the syntax − public bool IsBaseOf(Uri uri); Parameters uri − The specified Uri instance to test against the current Uri instance. Return Value Returns true if the current Uri instance is a base of the specified Uri; otherwise, false. ...
Read MoreC# String Operators
C# provides several string operators that allow you to perform operations and comparisons on strings. The primary string operators include equality (==), inequality (!=), and the concatenation operator (+). These operators make string manipulation and comparison straightforward and intuitive. Syntax Following is the syntax for string comparison operators − bool result = string1 == string2; // Equality bool result = string1 != string2; // Inequality string result = string1 + string2; // Concatenation String Equality Operator (==) The equality operator checks if two strings have the same content. It performs a ...
Read MoreRemove all objects from the Stack in C#
In C#, the Stack class provides the Clear() method to remove all objects from the Stack. This method efficiently removes every element from the Stack, leaving it empty with a count of zero. Syntax Following is the syntax for removing all objects from a Stack − stack.Clear(); Where stack is the instance of the Stack from which all elements need to be removed. How It Works The Clear()
Read MoreHow to find the number of times array is rotated in the sorted array by recursion using C#?
To find the number of times a sorted array has been rotated, we need to locate the position of the minimum element. The number of rotations equals the index of the minimum element. We can solve this efficiently using binary search recursion. In a rotated sorted array, the minimum element is the pivot point where the rotation occurred. For example, in array [4, 5, 6, 1, 2, 3], the minimum element 1 is at index 3, meaning the array was rotated 3 times. Algorithm The recursive binary search approach works as follows − Find ...
Read MoreC# BitConverter.ToUInt32() Method
The BitConverter.ToUInt32() method in C# converts four consecutive bytes from a byte array into a 32-bit unsigned integer. This method reads bytes in little-endian format, where the least significant byte comes first. Syntax public static uint ToUInt32(byte[] value, int startIndex); Parameters value − The byte array containing the data to convert. startIndex − The starting position within the byte array (must be between 0 and array length minus 4). Return Value Returns a 32-bit unsigned integer (uint) formed by four bytes beginning at startIndex. Little-Endian ...
Read MoreRemoving all entries from HybridDictionary in C#
A HybridDictionary in C# is part of the System.Collections.Specialized namespace that automatically switches between a ListDictionary and Hashtable based on the number of elements. To remove all entries from a HybridDictionary, you use the Clear() method. Syntax Following is the syntax for removing all entries from a HybridDictionary − hybridDictionary.Clear(); Using Clear() Method The Clear() method removes all key-value pairs from the HybridDictionary and sets the Count property to zero − Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() ...
Read MoreGetting an enumerator for the entire ArrayList in C#?
To get an enumerator for the entire ArrayList in C#, you use the GetEnumerator() method. This method returns an IEnumerator object that allows you to iterate through all elements in the ArrayList sequentially. An enumerator is a read-only, forward-only iterator that provides access to each element in a collection. Unlike a foreach loop, using an enumerator gives you explicit control over the iteration process. Syntax Following is the syntax for getting an enumerator for an ArrayList − IEnumerator enumerator = arrayList.GetEnumerator(); while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current); } Using GetEnumerator() with ...
Read More