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 32 of 2547
Get the minimum value in the SortedSet in C#
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 MoreDouble.IsNaN() Method in C#
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 MoreGet the number of elements actually contained in the ArrayList in C#
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 MoreConvert Class in C#
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 MoreHow to copy files into a directory in C#?
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 MoreStack.Equals() Method in C#
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 MoreDifference Between Delegates and Events in C#
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 MoreExplain and contrast value types and reference types in C#
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 MoreStack.GetEnumerator() Method in C#
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 MoreGet an enumerator that iterates through Collection in C#
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