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
Programming Articles
Page 113 of 2547
How to get Third Element of the Tuple in C#?
To get the third element of a Tuple in C#, you use the Item3 property. Tuples in C# provide indexed properties (Item1, Item2, Item3, etc.) to access their elements by position. Syntax Following is the syntax to access the third element of a tuple − var thirdElement = tuple.Item3; You can also create tuples using the generic Tuple class or the Tuple.Create() method − var tuple1 = new Tuple(10, 20, 30); var tuple2 = Tuple.Create(10, 20, 30); Using Item3 Property The Item3 property directly returns the third element of ...
Read MoreRemove a range of elements from the ArrayList in C#
The ArrayList class in C# provides the RemoveRange() method to remove a range of elements from the collection. This method is useful when you need to delete multiple consecutive elements efficiently in a single operation. Syntax Following is the syntax for the RemoveRange() method − public virtual void RemoveRange(int index, int count) Parameters index − The zero-based starting index of the range of elements to remove. count − The number of elements to remove. RemoveRange(index, count) Visual ...
Read MoreCopying the entire ArrayList to 1-D Array starting at the specified index in C#
The ArrayList class in C# provides the CopyTo() method to copy all its elements to a one-dimensional array starting at a specified index. This method is useful when you need to transfer data from a dynamic ArrayList to a fixed-size array. Syntax Following is the syntax for the CopyTo() method − public virtual void CopyTo(Array array, int arrayIndex) Parameters array − The one-dimensional array that is the destination of the elements copied from ArrayList. arrayIndex − The zero-based index in the array at which copying begins. ...
Read MoreC# Program to Get the relative path from two absolute paths
In C#, finding the relative path between two absolute paths is a common task when working with file systems. We can achieve this using the Uri class and its MakeRelativeUri method. This technique is useful for creating relative links between files or navigating within applications. An absolute path contains complete location information, such as C:\Program Files\Google\Chrome\filename.exe, while a relative path specifies location relative to the current directory, like Google\Chrome\filename.exe. Syntax Following is the syntax for creating URI instances and getting the relative path − Uri baseUri = new Uri(basePath); Uri targetUri = new Uri(targetPath); Uri ...
Read MoreHow to create a Stack in C#?
A Stack in C# is a generic collection that follows the Last-In-First-Out (LIFO) principle. Elements are added and removed from the top of the stack. The Stack class is part of the System.Collections.Generic namespace and provides type-safe stack operations. Syntax Following is the syntax for creating a Stack − Stack stackName = new Stack(); Common Stack operations − stack.Push(item); // Add element to top T item = stack.Pop(); // Remove and return top element T item = stack.Peek(); // Return top element without removing bool exists = stack.Contains(item); // ...
Read MoreC# Program to Find the Negative Double Numbers From the List of Objects Using LINQ
In this article, we will learn how to write a C# program to find the negative double numbers from a list of objects using LINQ. LINQ (Language Integrated Query) is a powerful feature in C# that allows developers to query data from various sources including arrays, collections, and databases. It provides SQL-like syntax for data manipulation and filtering, making complex data operations simple and readable. Problem Statement Given a list of objects containing different data types, we need to find only the negative double numbers using LINQ. This requires two filtering steps − Filter elements ...
Read MoreRemove all elements from the SortedSet in C#
To remove all elements from a SortedSet in C#, use the Clear() method. This method removes all elements from the SortedSet collection and resets the count to zero. Syntax Following is the syntax for the Clear() method − sortedSetName.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It simply removes all elements from the SortedSet. SortedSet.Clear() Operation Before Clear() {"AB", "BC", "CD", "EF"} Count = 4 ...
Read MoreHow to get a subset in a SortedSet in C#?
A SortedSet in C# provides the GetViewBetween() method to obtain a subset of elements within a specified range. This method returns a view that contains all elements between the lower and upper bounds, inclusive of both boundaries. Syntax Following is the syntax for getting a subset from a SortedSet − SortedSet subset = sortedSet.GetViewBetween(lowerValue, upperValue); Parameters lowerValue − The lowest desired value in the view (inclusive). upperValue − The highest desired value in the view (inclusive). Return Value The GetViewBetween() method returns a subset view that contains only the ...
Read MoreCheck if a HashSet is a proper superset of the specified collection in C#
The IsProperSupersetOf() method in C# checks if a HashSet is a proper superset of the specified collection. A proper superset means the HashSet contains all elements of the other collection plus at least one additional element. Syntax Following is the syntax for using the IsProperSupersetOf() method − public bool IsProperSupersetOf(IEnumerable other) Parameters other − The collection to compare with the current HashSet. Return Value Returns true if the HashSet is a proper superset of the specified collection; otherwise, false. Proper Superset Relationship ...
Read MoreCopying the HybridDictionary entries to an Array Instance in C#
The HybridDictionary class in C# provides a CopyTo() method that allows you to copy all dictionary entries to an array of DictionaryEntry objects. This method is useful when you need to convert dictionary data into array format for processing or storage. The HybridDictionary automatically switches between a ListDictionary (for small collections) and a Hashtable (for larger collections) to optimize performance based on the number of elements. Syntax Following is the syntax for copying HybridDictionary entries to an array − hybridDictionary.CopyTo(array, arrayIndex); Parameters array − The one-dimensional array of type DictionaryEntry ...
Read More