C# is an object-oriented programming language, making working with objects a common task. Object lists are fundamental building blocks of programming and are often used to store data, process it, or store the results of...
Tag - C# List
How to Create an ArrayList in C#
In C#, an ArrayList stores elements of multiple data types whose size can be changed dynamically. To create ArrayList in C#, we need to use the System.Collections namespace. Here is how we can create an arraylist in C#. C# //...
How to find the maximum and minimum number in a List in C#
In this blog post, I will be demonstrating how you can find the largest and smallest number in an array. Consider the following code snippet: C# Code: C# static void Main(string[] args) { List<int> list = new...
How to Search a C# List Elements?
In this tutorial, i’ll show you How to search C# List elements. The BinarySearch method of List<T> searches a sorted list and returns the zero-based index of the found item. The List<T> must be sorted before...
How to Reverse a C# List Elements?
The Reverse method of List<T> reverses the order all items in in the List. The following code snippet reverses a List. Example: C# static void Main(string[] args) { List<string> colors = new...
How to Insert Elements at a Position in a C# List?
The Insert method of List class inserts an object at a given position. The first parameter of the method is the 0th based index in the List. The InsertRange method can insert a collection at the given position. Add an item...
How to Create List in C#?
List is a generic class and is defined in the System.Collections.Generic namespace. You must import this namespace in your project to access the List<T> class. using System.Collections.Generic; 123 using System...
C# initialize list of objects
Instantiate list with values c# C# Code 1: C# class Program { static void Main(string[] args) { var list = new List<string> { "test1", "test2", "test3" }; list.ForEach(n => Console.WriteLine(n)); Console.ReadLine(); } }...
C# Read from Text File and Write to List
In this post we will read a data from a file and store them into a list using ReadAllLines method. C# Code: C# class Program { static void Main(string[] args) { // Specifying a file string path = @"E:\file.txt"; // Calling the...
C# List Find Examples
Example 1: Returns the first occurrence of item matching the specified predicate. C# using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var list = new...