Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the Capacity property of an ArrayList class in C#?

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

The Capacity property in the ArrayList class gets or sets the number of elements that the ArrayList can contain. This property represents the internal array size, which is automatically managed by the ArrayList to optimize performance. The capacity is always greater than or equal to the count of elements. When elements are added and the capacity is exceeded, the ArrayList automatically doubles its capacity to accommodate more elements. Syntax Following is the syntax for accessing the Capacity property − arrayListName.Capacity You can also set the capacity explicitly − arrayListName.Capacity = newCapacityValue; ...

Read More

Retrieving Elements from Collection in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 960 Views

Collections in C# provide various ways to retrieve elements. The List collection is one of the most commonly used collections that allows you to access elements by index, retrieve specific elements, or iterate through all elements. Syntax Following is the syntax for accessing elements by index − ElementType element = list[index]; Following is the syntax for using foreach to iterate through all elements − foreach (ElementType item in list) { // process item } Using Index-Based Access You can retrieve elements from a List collection using ...

Read More

Convert string to bool in C#

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

To convert a string to a bool in C#, you can use several methods. The most common approaches are bool.Parse(), bool.TryParse(), and Convert.ToBoolean(). Each method has different behaviors for handling invalid input. Syntax Following is the syntax for converting string to bool using different methods − bool result = bool.Parse(stringValue); bool result = Convert.ToBoolean(stringValue); bool.TryParse(stringValue, out bool result); Using bool.Parse() The bool.Parse() method converts a string representation of a boolean value to its boolean equivalent. It accepts "True" or "False" (case-insensitive) and throws an exception for invalid values − using System; ...

Read More

C# Linq FirstorDefault Method

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 20K+ Views

The FirstOrDefault() method in C# LINQ returns the first element of a sequence, or a default value if the sequence is empty or no element matches the specified condition. This method is useful when you need to safely retrieve the first element without throwing an exception. Syntax Following is the syntax for using FirstOrDefault() − // Without condition public static T FirstOrDefault(this IEnumerable source); // With condition public static T FirstOrDefault(this IEnumerable source, Func predicate); Parameters source − The sequence to return the first element from. predicate (optional) ...

Read More

Binary to decimal using C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 412 Views

Converting binary numbers to decimal is a fundamental operation in programming. In C#, you can convert binary to decimal using manual calculation methods or built-in functions. The binary number system uses base 2, where each digit position represents a power of 2. How Binary to Decimal Conversion Works Binary to decimal conversion follows a simple mathematical principle. Each binary digit (bit) is multiplied by the corresponding power of 2, starting from 2⁰ for the rightmost digit − Binary 1010 → Decimal 10 1 ...

Read More

What is the Count property of ArrayList class in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 349 Views

The Count property in the ArrayList class returns the number of elements currently stored in the ArrayList. This property is read-only and provides an efficient way to determine the size of the collection. Syntax Following is the syntax for accessing the Count property − int count = arrayListName.Count; Return Value The Count property returns an int value representing the total number of elements in the ArrayList. Using Count Property with ArrayList First, create an ArrayList and add elements to it − ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); ...

Read More

C# program to convert string to long

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

Converting a string to a long data type in C# can be accomplished using several methods. The most common approaches are long.Parse(), Convert.ToInt64(), and long.TryParse() for safe conversion. Syntax Following are the different syntaxes for converting string to long − long result = long.Parse(stringValue); long result = Convert.ToInt64(stringValue); bool success = long.TryParse(stringValue, out long result); Using long.Parse() Method The long.Parse() method converts a string representation of a number to its 64-bit signed integer equivalent − using System; class Demo { static ...

Read More

Int16.Equals Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 209 Views

The Int16.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int16. This method provides two overloads − one for comparing with another Int16 value and another for comparing with any object. Syntax Following is the syntax for both overloads − public bool Equals(short ob); public override bool Equals(object ob); Parameters For the first overload − ob − An Int16 value to compare to this instance. For the second overload − ob − The object to ...

Read More

Bitwise right shift operators in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 854 Views

The bitwise right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the bitwise right shift operator − result = operand >> numberOfPositions; How It Works When you right shift a binary number, each bit moves to the right by the specified number of positions. Vacant positions on the left are filled with zeros for positive numbers and ones for negative ...

Read More

Overriding Vs Shadowing in C#

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

In C#, overriding and shadowing are two different mechanisms for changing method behavior in derived classes. Overriding provides true polymorphism using virtual methods, while shadowing (method hiding) creates a new method that hides the base class method without polymorphic behavior. Overriding Overriding allows a subclass to provide a specific implementation of a method that is already defined in its base class. It requires the base class method to be marked as virtual or abstract, and the derived class method to use the override keyword. Method Overriding Base Class ...

Read More
Showing 10841–10850 of 61,297 articles
Advertisements