Articles on Trending Technologies

Technical articles with clear explanations and examples

How to check if a number is a power of 2 in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 712 Views

A power of 2 is a number of the form 2n where n is a non-negative integer. These numbers have a special property in their binary representation − they contain exactly one bit set to 1. For example, 8 = 23 has binary representation 1000, and 16 = 24 has binary representation 10000. n 2n Binary 0 1 0001 1 2 0010 2 4 0100 3 8 1000 4 16 10000 Bitwise Trick: n & ...

Read More

C# Check if HybridDictionary is read only

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 141 Views

The HybridDictionary class in C# provides a collection that uses a ListDictionary for small collections and switches to a Hashtable for larger collections. To check if a HybridDictionary is read-only, you can use the IsReadOnly property. Syntax Following is the syntax to check if a HybridDictionary is read-only − bool isReadOnly = hybridDictionary.IsReadOnly; Return Value The IsReadOnly property returns a bool value − true − if the HybridDictionary is read-only false − if the HybridDictionary allows modifications HybridDictionary Properties IsReadOnly ...

Read More

How to convert C# DateTime to "YYYYMMDDHHMMSS" format?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 5K+ Views

Converting a DateTime object to the "YYYYMMDDHHMMSS" format in C# is commonly needed for timestamps, file naming, and database operations. This format provides a compact, sortable representation of date and time without separators. The ToString() method with custom format strings allows you to convert DateTime objects to any desired string format using specific format specifiers. Syntax Following is the syntax for converting DateTime to "YYYYMMDDHHMMSS" format − DateTime dateTime = DateTime.Now; string formattedDate = dateTime.ToString("yyyyMMddHHmmss"); The format specifiers used are − yyyy − Four-digit year MM − Two-digit month (01-12) dd ...

Read More

C# program to calculate compound interest

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 5K+ Views

Compound interest is interest calculated on the initial principal amount plus all previously earned interest. Unlike simple interest, compound interest grows exponentially because the interest itself earns interest in subsequent periods. In this article, we will explore how to calculate compound interest using C#. What is Compound Interest? Compound Interest is the interest that calculates interest on both the initial principal and the accumulated interest from previous periods. This compounding effect causes the investment to grow at an accelerating rate over time. Compound Interest Growth Principal ...

Read More

How to get Second Element of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 370 Views

In C#, tuples are data structures that hold multiple values of different types. To access the second element of a tuple, you use the Item2 property. This property is available for all tuples that have at least two elements. Syntax Following is the syntax for accessing the second element of a tuple − var secondElement = tuple.Item2; You can also use tuple deconstruction to extract specific elements − var (first, second, _) = tuple; // _ ignores third element Using Item2 Property The Item2 property provides direct access ...

Read More

First occurrence in the List that matches the specified conditions in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 532 Views

To get the first occurrence in a list that matches the specified conditions in C#, you can use the Find() method. This method searches for an element that matches the conditions defined by the specified predicate and returns the first occurrence within the entire List. Syntax Following is the syntax for the Find() − public T Find(Predicate match) Parameters match − The Predicate delegate that defines the conditions to search for. Return Value Returns the first element that matches the conditions if found; otherwise, returns the default ...

Read More

How to create a folder if it does not exist in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 13K+ Views

Creating directories programmatically is a common task in C# applications. The System.IO namespace provides the necessary classes and methods to check for directory existence and create new folders when needed. It is always recommended to check if a directory exists before performing any file operations in C#, as the compiler will throw an exception if you attempt to access a non-existent folder. Syntax Following is the syntax for checking if a directory exists − bool exists = Directory.Exists(path); Following is the syntax for creating a directory − Directory.CreateDirectory(path); Using ...

Read More

C# Program to Calculate the Area of a Circle

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 5K+ Views

A circle is a round two-dimensional shape where all points on the boundary are equidistant from the center. The distance from the center to any point on the circle's edge is called the radius. Calculating the area of a circle is a fundamental geometric operation commonly used in programming. Formula for Circle Area The area of a circle is calculated using the formula − Area = π × r² Where: π (pi) ≈ 3.14159 or Math.PI in C# r is the radius of the circle Circle ...

Read More

How to get the remaining elements of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 168 Views

The Rest property in C# is used to get the remaining elements of a Tuple when it contains more than 7 elements. Since Tuple can hold a maximum of 8 elements, the 8th position (accessed via the Rest property) contains any additional elements as a nested Tuple. Syntax Following is the syntax for accessing the Rest property of a Tuple − var tuple = Tuple.Create(item1, item2, ..., item7, item8); var restElements = tuple.Rest; How It Works When a Tuple has exactly 8 elements, the Rest property returns the 8th element. When a Tuple ...

Read More

Remove element at specified index of Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 234 Views

To remove an element at a specified index from a Collection in C#, you use the RemoveAt() method. This method removes the element at the specified zero-based index and shifts all subsequent elements down by one position. Syntax Following is the syntax for the RemoveAt() method − collection.RemoveAt(index); Parameters index − The zero-based index of the element to remove. Must be a valid index within the collection bounds. Using RemoveAt() for Single Element Removal The following example demonstrates removing a single element at index 3 from a Collection − ...

Read More
Showing 9691–9700 of 61,297 articles
« Prev 1 968 969 970 971 972 6130 Next »
Advertisements