Programming Articles

Page 860 of 2547

What is the Values property of Hashtable class in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 180 Views

The Values property of the Hashtable class in C# gets an ICollection containing all the values stored in the Hashtable. This property provides a way to access all values without needing to know their corresponding keys. Syntax Following is the syntax for using the Values property − public virtual ICollection Values { get; } To iterate through the values − foreach (object value in hashtable.Values) { // process each value } Return Value The Values property returns an ICollection object that contains all the values ...

Read More

C# int.Parse Vs int.TryParse Method

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 6K+ Views

The int.Parse and int.TryParse methods in C# are used to convert string representations of numbers to integers. The key difference lies in how they handle conversion failures: int.Parse throws an exception when the string cannot be converted, while int.TryParse returns a boolean value indicating success or failure. Syntax Following is the syntax for int.Parse method − int result = int.Parse(string); Following is the syntax for int.TryParse method − bool success = int.TryParse(string, out int result); Using int.Parse Method The int.Parse method directly converts a valid string to an integer. ...

Read More

C# Enum GetValues Method

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

The Enum.GetValues() method in C# retrieves an array containing the values of all constants in a specified enumeration. This method is useful when you need to iterate through all enum values dynamically or perform operations on the entire set of enum values. Syntax Following is the syntax for the Enum.GetValues() method − public static Array GetValues(Type enumType) Parameters enumType − The Type of the enumeration whose values you want to retrieve. Return Value Returns an Array containing the values of the constants in the specified enumeration. Using GetValues() ...

Read More

Checked vs Unchecked Exceptions in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 4K+ Views

The checked and unchecked keywords in C# control whether arithmetic operations throw exceptions when overflow occurs. By default, C# ignores arithmetic overflow in most contexts, but you can explicitly enable or disable overflow checking using these keywords. In a checked context, arithmetic overflow throws an OverflowException. In an unchecked context, overflow is ignored and the result wraps around to the valid range. Syntax Following is the syntax for checked operations − int result = checked(expression); checked { // multiple statements } Following is the syntax for unchecked operations − ...

Read More

C# Program to remove duplicate characters from String

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 11K+ Views

Removing duplicate characters from a string is a common programming task in C#. There are several approaches to achieve this, with HashSet being one of the most efficient methods due to its automatic handling of unique elements. Using HashSet to Remove Duplicates The HashSet collection automatically maintains unique elements, making it perfect for removing duplicate characters from a string − using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string myStr = "kkllmmnnoo"; Console.WriteLine("Initial String: ...

Read More

How to calculate power of three using C#?

George John
George John
Updated on 17-Mar-2026 407 Views

Calculating the power of a number in C# can be done using recursion, iteration, or built-in methods. This article demonstrates how to calculate powers with a focus on raising numbers to the power of 3, though the methods work for any exponent. Syntax Following is the syntax for a recursive power function − static long power(int baseNumber, int exponent) { if (exponent != 0) { return (baseNumber * power(baseNumber, exponent - 1)); } return 1; } ...

Read More

How to access elements from multi-dimensional array in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 364 Views

To access elements from a multi-dimensional array in C#, you specify indices for each dimension using square brackets with comma-separated values. For example, a[2, 1] accesses the element at row 3, column 2 (using zero-based indexing). Syntax Following is the syntax for accessing elements from a multi-dimensional array − arrayName[index1, index2, ...indexN] For a 2D array, you use two indices − int element = array[rowIndex, columnIndex]; Understanding Array Indexing Multi-dimensional arrays use zero-based indexing, meaning the first element is at index [0, 0]. Consider this 4×2 array structure − ...

Read More

C# ToEven property

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 158 Views

The ToEven property is a value in the MidpointRounding enumeration that implements banker's rounding. When a number falls exactly between two integers, it rounds to the nearest even number. This method reduces bias in calculations compared to always rounding up or down. Syntax Following is the syntax for using MidpointRounding.ToEven − decimal.Round(value, digits, MidpointRounding.ToEven) Math.Round(value, digits, MidpointRounding.ToEven) Parameters value − The number to be rounded digits − Number of decimal places in the return value MidpointRounding.ToEven − Rounds to the nearest even number when the value is exactly halfway between two numbers ...

Read More

How to validate a URL using regular expression in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

To validate a URL using regular expressions in C#, you need to check for proper URL structure including protocols, domain names, and top-level domains. Regular expressions provide a powerful way to match URL patterns and ensure they conform to expected formats. URL Components to Validate A valid URL typically consists of the following components − Protocol: http or https Domain: The website name (e.g., example, google) Top-level domain: .com, .org, .net, .edu, etc. Optional path and query parameters: Additional URL components URL Structure Breakdown https:// ...

Read More

What is garbage collection in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 9K+ Views

The garbage collector (GC) in C# is an automatic memory management system that handles the allocation and release of memory for managed objects. It eliminates the need for manual memory management, preventing memory leaks and reducing programming errors. The garbage collector operates on the managed heap, where all reference type objects are stored. When objects are no longer referenced by the application, the GC automatically reclaims their memory space. How Garbage Collection Works Garbage Collection Process Object Created Memory Low ...

Read More
Showing 8591–8600 of 25,466 articles
« Prev 1 858 859 860 861 862 2547 Next »
Advertisements