How to find the number of times array is rotated in the sorted array by recursion using C#?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

392 Views

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 More

C# BitConverter.ToUInt32() Method

AmitDiwan
Updated on 17-Mar-2026 07:04:36

430 Views

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 More

Removing all entries from HybridDictionary in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

151 Views

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 More

Getting an enumerator for the entire ArrayList in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

171 Views

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

C# Program to Search Sub-Directory in a Given Directory

Sabid Ansari
Updated on 17-Mar-2026 07:04:36

648 Views

Searching for sub-directories in a given directory is a common task in many applications. In C#, we can use the Directory and DirectoryInfo classes provided by the System.IO namespace to perform this task. In this article, we will explore how to write a C# program to search for sub-directories in a given directory. Syntax Following is the syntax for using DirectoryInfo.GetDirectories() method − DirectoryInfo directoryInfo = new DirectoryInfo(path); DirectoryInfo[] subdirectories = directoryInfo.GetDirectories(); Following is the syntax for using Directory.GetDirectories() method − string[] subdirectories = Directory.GetDirectories(path); Using DirectoryInfo.GetDirectories() The DirectoryInfo.GetDirectories() ... Read More

C# BitConverter.ToUInt64 Method

AmitDiwan
Updated on 17-Mar-2026 07:04:36

360 Views

The BitConverter.ToUInt64() method in C# converts eight consecutive bytes from a byte array into a 64-bit unsigned integer (ulong). This method is useful when you need to reconstruct numeric values from byte data, such as reading from binary files or network streams. Syntax public static ulong ToUInt64(byte[] value, int startIndex); Parameters value − The byte array containing the bytes to convert. startIndex − The starting position within the byte array (must have at least 8 bytes from this position). Return Value Returns a 64-bit unsigned integer (ulong) formed by eight ... Read More

Get an enumerator that iterates through the Hashtable in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

420 Views

To get an enumerator that iterates through the Hashtable in C#, you use the GetEnumerator() method. This method returns an IDictionaryEnumerator that provides key-value pair access to the hashtable elements. Syntax Following is the syntax for getting an enumerator from a Hashtable − IDictionaryEnumerator enumerator = hashtable.GetEnumerator(); The enumerator provides the following key members − enumerator.MoveNext() // advances to next element, returns bool enumerator.Key // gets current key enumerator.Value // gets current value enumerator.Entry ... Read More

Char Struct in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

462 Views

The Char struct in C# represents a single Unicode character as a UTF-16 code unit. It provides numerous static methods for character classification, conversion, and comparison operations. The Char struct is a value type that implements IComparable, IConvertible, and IEquatable interfaces. Key Char Methods Method Description ConvertToUtf32(Char, Char) Converts the value of a UTF-16 encoded surrogate pair into a Unicode code point. ConvertToUtf32(String, Int32) Converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point. ... Read More

How to convert XML to Json and Json back to XML using Newtonsoft.json?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

3K+ Views

Newtonsoft.Json (Json.NET) provides powerful methods for converting between XML and JSON formats. The library preserves all XML features including elements, attributes, text content, comments, character data, processing instructions, namespaces, and XML declarations during conversion. Required NuGet Package Install the Newtonsoft.Json package to use these conversion methods − Install-Package Newtonsoft.Json Key Methods The JsonConvert class provides two essential methods for XML-JSON conversion − SerializeXmlNode() − Converts XML to JSON format DeserializeXmlNode() − Converts JSON back to XML format Converting XML to JSON Use SerializeXmlNode() to convert an XmlDocument or ... Read More

TimeSpan.FromDays() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

758 Views

The TimeSpan.FromDays() method in C# is used to create a TimeSpan object that represents a specified number of days. This static method is particularly useful when you need to work with time intervals measured in days and want to convert them to a TimeSpan for calculations or comparisons. Syntax Following is the syntax for the TimeSpan.FromDays() method − public static TimeSpan FromDays(double value); Parameters value: A double-precision floating-point number representing the number of days. The value can be positive, negative, or zero, and is accurate to the nearest millisecond. Return Value ... Read More

Advertisements