
- 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
How to access elements from an array in C#?
First, define and initalize an array −
int[] p = new int[3] {99, 92, 95};
Now, display the array elements −
for (j = 0; j < 3; j++ ) { Console.WriteLine("Price of Product[{0}] = {1}", j, p[j]); }
To acess any element, just include the index of the element you want like this −
p[2];
The above is to acess the 3rd element.
Now let us see the complete code −
Example
using System; namespace Program { class Demo { static void Main(string[] args) { int[] p = new int[3] {99, 92, 95}; int j; for (j = 0; j < 3; j++ ) { Console.WriteLine("Price of Product[{0}] = {1}", j, p[j]); } // access int e = p[2]; Console.WriteLine("Product 3rd price: "+e); Console.ReadKey(); } } }
- Related Articles
- How to access elements from jagged array in C#?
- How to access elements from multi-dimensional array in C#?
- How to access elements from a rectangular array in C#?
- How to access elements of an array using pointer notation in C#?
- How to delete elements from an array?
- How do we access elements from the two-dimensional array in C#?
- C++ Program to Access Elements of an Array Using Pointer
- How to access array elements using a pointer in C#?
- How to remove duplicate elements from an array in JavaScript?
- JavaScript - How to pick random elements from an array?
- How to access an array element in C language?
- How to get Synchronize access to an Array in C#?
- How to remove certain number elements from an array in JavaScript
- How to filter an array from all elements of another array – JavaScript?
- MongoDB query to access an object in an array

Advertisements