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

AmitDiwan
Updated on 17-Mar-2026 07:04:36

207 Views

To access the sixth element of a Tuple in C#, you use the Item6 property. This property is available for tuples that contain six or more elements. Tuples in C# are immutable data structures that can store multiple values of different types. Syntax Following is the syntax to access the sixth element of a tuple − var sixthElement = tuple.Item6; The Item6 property returns the value stored at the sixth position in the tuple. Using Item6 Property The following example demonstrates how to create a 7-tuple and access its sixth element using ... Read More

How to create a SortedList in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

169 Views

A SortedList in C# is a collection that stores key-value pairs in sorted order based on the keys. It combines the functionality of arrays and hashtables, automatically maintaining elements in ascending order of keys. Unlike regular lists, SortedList provides efficient searching and maintains order without manual sorting. Syntax Following is the syntax for creating a SortedList − SortedList sortedList = new SortedList(); sortedList.Add(key, value); You can also specify initial capacity − SortedList sortedList = new SortedList(capacity); Key Features Automatic Sorting: Elements are automatically sorted by key in ... Read More

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

AmitDiwan
Updated on 17-Mar-2026 07:04:36

180 Views

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 More

Remove a range of elements from the ArrayList in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

195 Views

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 More

Copying the entire ArrayList to 1-D Array starting at the specified index in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

128 Views

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 More

C# Program to Get the relative path from two absolute paths

Ankit kumar
Updated on 17-Mar-2026 07:04:36

6K+ Views

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 More

How to create a Stack in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

171 Views

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 More

C# Program to Find the Negative Double Numbers From the List of Objects Using LINQ

Ankit kumar
Updated on 17-Mar-2026 07:04:36

587 Views

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 More

Remove all elements from the SortedSet in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

187 Views

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 More

How to get a subset in a SortedSet in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

207 Views

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 More

Advertisements