Csharp Articles

Page 39 of 196

Check if a thread belongs to managed thread pool or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 257 Views

The IsThreadPoolThread property in C# helps determine whether a thread belongs to the managed thread pool. This property returns true if the thread is from the thread pool, and false if it's a manually created thread. Understanding this distinction is important because thread pool threads are managed by the runtime and optimized for short-running tasks, while manually created threads give you more control but require more resources. Syntax Following is the syntax for checking if a thread belongs to the managed thread pool − bool isPoolThread = Thread.CurrentThread.IsThreadPoolThread; Manual Thread vs Thread Pool ...

Read More

Convert the specified Windows file time to an equivalent local time in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 306 Views

To convert the specified Windows file time to an equivalent local time in C#, you can use the DateTimeOffset.FromFileTime() method. This method converts a Windows file time (represented as a 64-bit integer) to a DateTimeOffset value that represents the equivalent local time. Windows file time is measured as the number of 100-nanosecond intervals that have elapsed since January 1, 1601 UTC. The FromFileTime method automatically adjusts the result to the local time zone of the system. Syntax Following is the syntax for converting Windows file time to local time − DateTimeOffset localTime = DateTimeOffset.FromFileTime(fileTime); ...

Read More

Get an ICollection containing keys in OrderedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 204 Views

The OrderedDictionary class in C# maintains the insertion order of elements. To get an ICollection containing keys from an OrderedDictionary, you can use the Keys property which returns an ICollection object containing all the keys in their insertion order. Syntax Following is the syntax to get keys as an ICollection from OrderedDictionary − OrderedDictionary dict = new OrderedDictionary(); ICollection keys = dict.Keys; Using Keys Property with CopyTo Method The most common approach is to use the Keys property and copy the keys to a string array using the CopyTo method − ...

Read More

Check if HashSet and the specified collection contain the same elements in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 211 Views

To check if a HashSet and another collection contain the same elements in C#, use the SetEquals() method. This method returns true if both collections have identical elements, regardless of order, and false otherwise. Syntax Following is the syntax for the SetEquals() method − public bool SetEquals(IEnumerable other) Parameters other − The collection to compare with the current HashSet. Return Value Returns true if the HashSet and the specified collection contain the same elements; otherwise, false. Using SetEquals() with Different Elements When the HashSet and another collection ...

Read More

Capacity of a List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 384 Views

The Capacity property of a List in C# represents the total number of elements the internal array can hold before needing to be resized. This is different from the Count property, which represents the actual number of elements currently stored in the list. Understanding capacity is important for performance optimization, as the list automatically doubles its capacity when more space is needed, which involves allocating a new array and copying existing elements. Syntax Following is the syntax to get the capacity of a list − int capacity = listName.Capacity; You can also set ...

Read More

Convert the value of the current DateTime object to UTC in C#

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

To convert the value of the current DateTime object to Coordinated Universal Time (UTC), C# provides the ToUniversalTime() method. This method converts a local time or unspecified DateTime to its equivalent UTC representation. Syntax Following is the syntax for the ToUniversalTime() method − DateTime utcDateTime = localDateTime.ToUniversalTime(); Return Value The ToUniversalTime() method returns a new DateTime object that represents the UTC equivalent of the original DateTime. If the original DateTime's Kind property is DateTimeKind.Utc, it returns the same value unchanged. Local Time to UTC Conversion ...

Read More

Get the hash code for the current Decimal instance in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 203 Views

The GetHashCode() method in C# returns a 32-bit signed integer hash code for the current Decimal instance. This hash code is used internally by collections like HashSet and Dictionary to efficiently store and retrieve decimal values. Hash codes are essential for the proper functioning of hash-based collections, as they provide a quick way to categorize and locate objects. Two Decimal instances that are equal will always return the same hash code, but different decimal values may occasionally produce the same hash code (hash collision). Syntax Following is the syntax for getting the hash code of a Decimal ...

Read More

Convert Decimal to equivalent 8-bit unsigned integer in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 358 Views

To convert a Decimal value to an equivalent 8-bit unsigned integer (byte), C# provides the Decimal.ToByte() method. This method truncates the decimal portion and converts the integer part to a byte value, which ranges from 0 to 255. The conversion follows banker's rounding rules for values exactly between two integers, and throws an OverflowException if the decimal value is outside the valid byte range. Syntax Following is the syntax for converting decimal to byte − byte result = Decimal.ToByte(decimalValue); Parameters decimalValue − The decimal number to convert to a byte. Must ...

Read More

Check whether the Unicode character is a separator character in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 304 Views

The Char.IsSeparator() method in C# determines whether a Unicode character belongs to the separator category. Unicode separator characters are used to separate words, lines, or paragraphs in text, such as spaces, line separators, and paragraph separators. Syntax Following is the syntax for the Char.IsSeparator() method − public static bool IsSeparator(char c) public static bool IsSeparator(string s, int index) Parameters c − The Unicode character to evaluate. s − A string containing the character to evaluate. index − The position of the character to evaluate in the string. Return Value ...

Read More

Capacity of a SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 220 Views

The Capacity property of a SortedList in C# represents the maximum number of key-value pairs that the SortedList can hold without needing to resize its internal storage. This is different from the Count property, which shows the actual number of elements currently stored. When elements are added to a SortedList, the capacity automatically grows to accommodate new items. The capacity typically doubles when the current capacity is exceeded, following a geometric growth pattern to optimize performance. Syntax Following is the syntax to get the capacity of a SortedList − int capacity = sortedList.Capacity; ...

Read More
Showing 381–390 of 1,951 articles
« Prev 1 37 38 39 40 41 196 Next »
Advertisements