The LinkedList.Find() method in C# searches for the first node that contains the specified value and returns a LinkedListNode object. If the value is not found, it returns null. Syntax Following is the syntax for the Find() − public LinkedListNode Find(T value); Parameters value − The value to locate in the LinkedList. Return Value Returns the first LinkedListNode that contains the specified value, or null if the value is not found. Using Find() with String Values Example using System; using System.Collections.Generic; public class Demo ... Read More
A deep copy in C# creates a completely independent copy of an object, including all its nested objects and reference types. Unlike a shallow copy that only copies references, a deep copy duplicates the entire object hierarchy, ensuring that changes to the copied object do not affect the original. Deep copying is essential when working with complex objects containing reference types like arrays, lists, or custom objects. Without proper deep copying, modifications to nested objects can unexpectedly affect the original object. Shallow Copy vs Deep Copy Shallow Copy ... Read More
To get an ICollection containing the keys in HybridDictionary, you use the Keys property. The HybridDictionary class is part of the System.Collections.Specialized namespace and provides a collection that uses a ListDictionary for small collections and switches to a Hashtable for larger collections automatically. The Keys property returns an ICollection that contains all the keys in the dictionary, which can then be iterated over or copied to an array. Syntax Following is the syntax for accessing the Keys property − ICollection keys = hybridDictionary.Keys; To copy keys to an array − string[] ... Read More
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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance