Programming Articles

Page 101 of 2547

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

Sabid Ansari
Sabid Ansari
Updated on 17-Mar-2026 639 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
AmitDiwan
Updated on 17-Mar-2026 357 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
AmitDiwan
Updated on 17-Mar-2026 416 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
AmitDiwan
Updated on 17-Mar-2026 455 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
Nizamuddin Siddiqui
Updated on 17-Mar-2026 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
AmitDiwan
Updated on 17-Mar-2026 752 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

Get the minimum value in the SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 180 Views

The SortedSet class in C# provides built-in properties to efficiently retrieve the minimum and maximum values. The Min property returns the smallest element, while the Max property returns the largest element in the sorted collection. Since SortedSet maintains elements in sorted order, accessing the minimum and maximum values is an O(1) operation, making it very efficient for scenarios where you frequently need these extreme values. Syntax Following is the syntax to get the minimum value from a SortedSet − T minValue = sortedSet.Min; Following is the syntax to get the maximum value from ...

Read More

Double.IsNaN() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 768 Views

The Double.IsNaN() method in C# is used to determine whether a specified double value is "Not a Number" (NaN). This static method returns true if the value represents NaN, and false otherwise. NaN values typically result from invalid mathematical operations like dividing zero by zero. Syntax Following is the syntax for the Double.IsNaN() method − public static bool IsNaN(double val); Parameters val − A double-precision floating-point number to test. Return Value Returns true if the value is NaN; otherwise, false. Double.IsNaN() Results ...

Read More

Get the number of elements actually contained in the ArrayList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 145 Views

The Count property in C# is used to get the number of elements actually contained in an ArrayList. This property returns an integer representing the current number of elements, which is different from the Capacity property that indicates the total storage space available. Syntax Following is the syntax for using the Count property − int elementCount = arrayListName.Count; Count vs Capacity Count Property Capacity Property Returns the actual number of elements stored Returns the total storage space available Changes when elements are added or ...

Read More

Convert Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 789 Views

The Convert class in C# provides static methods to convert between different base data types. It offers type-safe conversion methods that can handle null values and format providers, making it more robust than direct casting for many scenarios. The Convert class includes methods like ToBoolean(), ToDouble(), ToDecimal(), ToInt32(), and many others, each designed to convert values to their respective target types while handling edge cases and cultural formatting. Convert.ToBoolean() Method The Convert.ToBoolean() method converts a specified value to an equivalent Boolean value − Syntax public static bool ToBoolean(string value, IFormatProvider provider); public static bool ...

Read More
Showing 1001–1010 of 25,467 articles
« Prev 1 99 100 101 102 103 2547 Next »
Advertisements