
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Get or set the element at the specified index in ArrayList in C#
To get or set the element at the specified index in ArrayList, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add("Laptop"); arrList.Add("Desktop"); arrList.Add("Notebook"); arrList.Add("Ultrabook"); arrList.Add("Tablet"); arrList.Add("Headphone"); arrList.Add("Speaker"); Console.WriteLine("Elements in ArrayList..."); foreach(string str in arrList) { Console.WriteLine(str); } Console.WriteLine("Element at index 5 = " + arrList[5]); } }
Output
This will produce the following output −
Elements in ArrayList... Laptop Desktop Notebook Ultrabook Tablet Headphone Speaker Element at index 5 = Headphone
Example
Let us see another example −
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add("Laptop"); arrList.Add("Desktop"); arrList.Add("Notebook"); arrList.Add("Ultrabook"); arrList.Add("Tablet"); arrList.Add("Headphone"); arrList.Add("Speaker"); Console.WriteLine("Elements in ArrayList..."); foreach(string str in arrList) { Console.WriteLine(str); } Console.WriteLine("Element at index 5 = " + arrList[5]); arrList[5] = "SSD"; Console.WriteLine("Element at index 5 (Updated) = " + arrList[5]); } }
Output
This will produce the following output −
Elements in ArrayList... Laptop Desktop Notebook Ultrabook Tablet Headphone Speaker Element at index 5 = Headphone Element at index 5 (Updated) = SSD
- Related Articles
- Get or set the element at specified index in Collection in C#
- Get or Set at specified index in StringCollection in C#
- Remove the element at the specified index of the ArrayList in C#
- Insert an element into the ArrayList at the specified index in C#
- Gets or sets the element at the specified index in StringCollection in C#
- Gets or Sets the element at the specified index in the List in C#
- Add an element to specified index of ArrayList in Java
- Get the index of a particular element in an ArrayList in Java
- Copying the entire ArrayList to 1-D Array starting at the specified index in C#
- Get the last index of a particular element in an ArrayList in Java
- Remove element at specified index of Collection in C#
- Replace an element at a specified index of the Vector in Java
- Insert an element into Collection at specified index in C#
- Get the unmodifiable view of the specified ArrayList in Java
- Golang Program to insert an element into the array at the specified index

Advertisements