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
Articles by AmitDiwan
Page 189 of 840
Insert a new entry in OrderedDictionary with specified key and value in C#
The OrderedDictionary class in C# provides the Insert method to add a new entry at a specific position while maintaining the order of existing elements. This method allows you to specify both the index position and the key-value pair to insert. Syntax Following is the syntax for inserting an entry at a specific position in an OrderedDictionary − orderedDictionary.Insert(index, key, value); Parameters index − The zero-based index at which to insert the key-value pair. key − The key of the entry to insert. value − The value ...
Read MoreUri.IsWellFormedOriginalString() Method in C#
The Uri.IsWellFormedOriginalString() method in C# determines whether the original string used to construct a Uri object was well-formed and doesn't require additional escaping. This method returns true if the URI string is properly formatted according to RFC standards, and false otherwise. This method is particularly useful when validating URI strings before processing them or when you need to ensure that a URI doesn't contain characters that require percent-encoding. Syntax Following is the syntax for the IsWellFormedOriginalString() method − public bool IsWellFormedOriginalString(); Return Value The method returns a bool value − ...
Read MoreTimeSpan.Compare() Method in C#
The TimeSpan.Compare() method in C# is a static method used to compare two TimeSpan values and returns an integer that indicates their relative relationship. This method is useful for sorting operations and determining the order of time intervals. Syntax Following is the syntax for the TimeSpan.Compare() method − public static int Compare(TimeSpan span1, TimeSpan span2); Parameters span1 − The first TimeSpan value to compare. span2 − The second TimeSpan value to compare. Return Value The method returns an integer with the following meaning − Return ...
Read MoreGet the number of elements in the SortedSet in C#
The Count property in C# returns the number of elements currently stored in a SortedSet. This property provides an efficient way to determine the size of the collection without having to iterate through all elements. Syntax Following is the syntax for getting the count of elements in a SortedSet − int elementCount = sortedSet.Count; Return Value The Count property returns an int value representing the total number of elements in the SortedSet. For an empty SortedSet, it returns 0. Using Count Property with String SortedSet The following example demonstrates how to ...
Read MoreNumber of elements in HashSet in C#?
To get the number of elements in a HashSet in C#, use the Count property. The Count property returns an integer representing the total number of unique elements stored in the HashSet. Syntax Following is the syntax for getting the count of elements in a HashSet − HashSet hashSet = new HashSet(); int count = hashSet.Count; Using Count Property with Integer HashSet The following example demonstrates how to get the number of elements in HashSets containing integers − using System; using System.Collections.Generic; public class Demo { public ...
Read MoreUInt64 Struct in C#
The UInt64 struct in C# represents a 64-bit unsigned integer with values ranging from 0 to 18, 446, 744, 073, 709, 551, 615. This struct provides various methods for comparison, equality checks, and other operations on unsigned 64-bit integers. UInt64 Value Range 0 18, 446, 744, 073, 709, 551, 615 64-bit Unsigned Integer 2^64 - 1 possible values UInt64.CompareTo() Method The UInt64.CompareTo() method compares the current instance to a specified object or UInt64 value and returns an indication of their ...
Read MoreInsert at the specified index in StringCollection in C#
The StringCollection class in C# provides the Insert() method to add elements at specific positions within the collection. This method shifts existing elements to the right to make room for the new element at the specified index. Syntax Following is the syntax for the Insert() method − stringCollection.Insert(index, value); Parameters index − The zero-based index at which to insert the element. value − The string value to insert into the collection. Using Insert() Method Example using System; using System.Collections.Specialized; public class Demo { ...
Read MoreHow to check whether a thread is a background thread or not in C#
In C#, you can check whether a thread is a background thread using the IsBackground property of the Thread class. Background threads are automatically terminated when all foreground threads complete, while foreground threads keep the application running until they finish execution. Syntax Following is the syntax to check if a thread is a background thread − bool isBackground = thread.IsBackground; To set a thread as a background thread − thread.IsBackground = true; Understanding Background vs Foreground Threads Background vs Foreground Threads ...
Read MoreDecimal Struct in C#
The Decimal struct in C# represents a high-precision decimal floating-point number ideal for financial and monetary calculations. The Decimal value type represents decimal numbers ranging from positive 79, 228, 162, 514, 264, 337, 593, 543, 950, 335 to negative 79, 228, 162, 514, 264, 337, 593, 543, 950, 335. The default value of a Decimal is 0. The Decimal struct provides better precision than float or double for calculations where exact decimal representation is crucial, such as currency operations. Decimal vs Float Precision Comparison Decimal 0.1 + ...
Read MoreSortedDictionary.ContainsValue() Method in C#
The SortedDictionary.ContainsValue() method in C# is used to determine whether the SortedDictionary contains an element with the specified value. This method performs a linear search through all values in the collection. Syntax Following is the syntax of the ContainsValue() method − public bool ContainsValue(TValue value) Parameters value − The value to be searched in the SortedDictionary. The value can be null for reference types. Return Value Returns true if the SortedDictionary contains an element with the specified value; otherwise, false. Using ContainsValue() to Check Existing Values The following example ...
Read More