Articles on Trending Technologies

Technical articles with clear explanations and examples

Remove all elements from the ArrayList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 302 Views

To remove all elements from an ArrayList in C#, you can use the Clear() method. This method removes all elements from the ArrayList and sets the Count property to zero. Syntax Following is the syntax for the Clear() method − arrayList.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It is a void method that modifies the ArrayList in-place. Using Clear() to Remove All Elements The following example demonstrates how to use the Clear() method to remove all ...

Read More

C# Program to Find the List of Students whose Name Starts with ‘S’ using where() Method of List Collection using LINQ

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 674 Views

The Where() method in LINQ is a powerful filtering tool that allows you to query collections based on specific conditions. This article demonstrates how to use the Where() method with a List collection to find students whose names start with the letter 'S'. LINQ (Language Integrated Query) is a .NET framework feature that provides a consistent way to query different data sources using C# syntax. It eliminates the need for separate query languages like SQL when working with in-memory collections, making data filtering and manipulation more intuitive. Syntax The Where() method has the following syntax − ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 281 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
AmitDiwan
Updated on 17-Mar-2026 228 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
AmitDiwan
Updated on 17-Mar-2026 214 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
AmitDiwan
Updated on 17-Mar-2026 256 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
AmitDiwan
Updated on 17-Mar-2026 203 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
Ankit kumar
Updated on 17-Mar-2026 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
AmitDiwan
Updated on 17-Mar-2026 223 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
Ankit kumar
Updated on 17-Mar-2026 661 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
Showing 9661–9670 of 61,299 articles
« Prev 1 965 966 967 968 969 6130 Next »
Advertisements