Programming Articles

Page 32 of 2547

Get the minimum value in the SortedSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 178 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 764 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 142 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 781 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

How to copy files into a directory in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 4K+ Views

To copy files in C#, the File.Copy method is the primary approach. This method allows you to copy individual files from one location to another, with options to control whether existing files should be overwritten. Syntax The File.Copy method has two overloads − File.Copy(string sourceFileName, string destFileName) File.Copy(string sourceFileName, string destFileName, bool overwrite) Parameters sourceFileName − The file to copy. destFileName − The name of the destination file. This cannot be a directory. overwrite − true if the destination file should be overwritten if it already exists; otherwise, false. ...

Read More

Stack.Equals() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 368 Views

The Stack.Equals() method in C# is used to check whether a Stack class object is equal to another object or not. This method performs reference equality, not content equality, meaning it returns true only if both variables reference the same Stack object in memory. Syntax Following is the syntax for the Stack.Equals() method − public virtual bool Equals(object obj); Parameters obj − The object to compare with the current Stack instance. Return Value Returns true if the specified object is the same instance as the current Stack; otherwise, false. ...

Read More

Difference Between Delegates and Events in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

In C#, both delegates and events are used for callback mechanisms, but they serve different purposes and have distinct characteristics. Understanding their differences is crucial for proper C# programming and design patterns. Delegates A delegate is a type that represents references to methods with a specific signature. It acts as a function pointer that can hold references to one or more methods during runtime. Syntax public delegate returnType DelegateName(parameters); Example using System; public delegate void MyDelegate(string message); public class DelegateExample { public static void Method1(string ...

Read More

Explain and contrast value types and reference types in C#

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 410 Views

In C#, all types can be divided into two main categories − value types and reference types. Understanding the difference between these types is crucial for memory management and avoiding common programming errors. Value Types Variables of value types directly contain their data. Each variable has its own copy of the data, stored on the stack. When you assign one value type variable to another, the entire value is copied. Value types in C# include − All numeric types: int, float, double, decimal, byte, etc. char and bool types struct ...

Read More

Stack.GetEnumerator() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 152 Views

The Stack.GetEnumerator() method in C# returns an IEnumerator that allows you to iterate through the elements of a Stack collection. This method provides a way to manually control the iteration process using the enumerator pattern, as an alternative to using foreach loops. Syntax Following is the syntax for the GetEnumerator() method − public virtual System.Collections.IEnumerator GetEnumerator(); Return Value The method returns an IEnumerator object that can be used to iterate through the Stack elements. The enumerator starts before the first element and advances using MoveNext(), with the current element accessed via the Current ...

Read More

Get an enumerator that iterates through Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 154 Views

To get an enumerator that iterates through a Collection in C#, you use the GetEnumerator() method. An enumerator provides a way to iterate through collection elements one by one using MoveNext() and Current properties. The Collection class is part of the System.Collections.ObjectModel namespace and provides a generic collection that can be customized by inheritance. Syntax Following is the syntax for getting and using an enumerator − var enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { // Access current element using enumerator.Current } How It Works GetEnumerator() returns an IEnumerator ...

Read More
Showing 311–320 of 25,467 articles
« Prev 1 30 31 32 33 34 2547 Next »
Advertisements