Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to delete all files and folders from a path in C#?
Deleting all files and folders from a directory is a common task in C# file operations. The System.IO namespace provides the DirectoryInfo class and Directory class that offer multiple approaches to accomplish this task safely and efficiently. Syntax Following is the syntax for using DirectoryInfo to delete directories and files − DirectoryInfo di = new DirectoryInfo(path); di.Delete(true); // true = recursive delete Following is the syntax for using Directory class methods − Directory.Delete(path, true); // true = recursive delete Using DirectoryInfo for Recursive Deletion The DirectoryInfo class provides detailed ...
Read MoreRemove entry with specified key from OrderedDictionary in C#
The OrderedDictionary class in C# provides the Remove() method to remove entries with a specified key. The OrderedDictionary maintains the insertion order of elements while allowing both key-based and index-based access. Syntax Following is the syntax for removing an entry by key from an OrderedDictionary − orderedDictionary.Remove(key); Parameters key − The key of the entry to remove from the OrderedDictionary. Return Value The Remove() method does not return a value. It removes the entry if the key exists, or does nothing if the key is not found. ...
Read MoreHow to create a shallow copy of SortedList Object in C#?
The shallow copy of a SortedList object in C# creates a new SortedList instance with the same key-value pairs as the original, but both collections share references to the same objects. This is accomplished using the Clone() method. Syntax Following is the syntax for creating a shallow copy of SortedList − SortedList clonedList = (SortedList)originalList.Clone(); What is a Shallow Copy? A shallow copy creates a new collection object, but the elements inside both the original and copied collections point to the same memory locations. For value types like strings and integers, this behaves ...
Read MoreWhat is the main difference between int.Parse() and Convert.ToInt32 in C#?
Both int.Parse() and Convert.ToInt32() methods in C# are used to convert string representations of numbers to integers. However, they handle null values and certain edge cases differently. The key difference is that Convert.ToInt32() handles null values gracefully by returning 0, while int.Parse() throws an ArgumentNullException when encountering null. Syntax Following is the syntax for int.Parse() method − int result = int.Parse(stringValue); Following is the syntax for Convert.ToInt32() method − int result = Convert.ToInt32(stringValue); Using int.Parse() with Valid String The int.Parse() method converts a valid numeric string to an ...
Read MoreRemove entry with specified key from the StringDictionary in C#
The StringDictionary class in C# provides the Remove() method to delete entries with a specified key. This method removes both the key and its associated value from the collection. StringDictionary is case-insensitive, meaning keys are automatically converted to lowercase. Syntax Following is the syntax for the Remove() method − public virtual void Remove(string key) Parameters key − The string key to remove from the StringDictionary. Using Remove() Method Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() ...
Read MoreHow to get hash code for the specified key of a Hashtable in C#?
To get the hash code for a specified key in a Hashtable, you need to use the GetHash() method. This method is protected in the base Hashtable class, so you must create a derived class to access it. The hash code is an integer value used internally by the hashtable to determine where to store the key-value pair. Syntax Following is the syntax to access the protected GetHash() method − public class CustomHashtable : Hashtable { public int GetHashCodeForKey(object key) { return GetHash(key); } ...
Read MoreHow can we update the values of a collection using LINQ in C#?
LINQ provides several approaches to update collection values in C#. While LINQ is primarily designed for querying data, you can combine it with other methods to modify collection elements efficiently. Using ForEach with List Collections The List class provides a ForEach method that can be used to update all elements in the collection − using System; using System.Collections.Generic; namespace DemoApplication { class Program { static void Main(string[] args) { List fruits ...
Read MoreRemove from the specified index of a SortedList in C#
The SortedList class in C# provides the RemoveAt() method to remove a key-value pair from a specified index. The RemoveAt() method removes the element at the specified zero-based index and automatically shifts the remaining elements to fill the gap. Syntax Following is the syntax for the RemoveAt() method − public virtual void RemoveAt(int index) Parameters index − The zero-based index of the element to remove. Key Points The index is zero-based, meaning the first element is at index 0. After removal, all elements at higher indices are shifted ...
Read MoreHow to create a StringCollection in C#?
The StringCollection class in C# is a specialized collection that stores only string values. It is part of the System.Collections.Specialized namespace and provides methods to add, remove, and manipulate strings efficiently. StringCollection is useful when you need to work exclusively with string data and want type safety without the overhead of generic collections. Syntax Following is the syntax for creating a StringCollection − StringCollection collection = new StringCollection(); To add multiple strings at once using an array − string[] array = {"string1", "string2", "string3"}; collection.AddRange(array); Creating and Populating a ...
Read MoreDifference between SortedList and SortedDictionary in C#
Both SortedList and SortedDictionary in C# are generic collections that store key-value pairs in sorted order based on the key. However, they differ significantly in their internal implementation, memory usage, and performance characteristics. Understanding these differences helps you choose the right collection for your specific use case based on performance requirements and usage patterns. Syntax Following is the syntax for declaring a SortedList − SortedList sortedList = new SortedList(); Following is the syntax for declaring a SortedDictionary − SortedDictionary sortedDictionary = new SortedDictionary(); Key Differences ...
Read More