- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set a value to the element at the specified position in the one-dimensional array in C#
Firstly, set the array −
int[] p = new int[] {55, 66, 88, 99, 111, 122, 133};
Now, let us say you need to set an element at position 1 −
p[2] = 77;
Let us see the comple code −
Example
using System; namespace Program { public class Demo { public static void Main(string[] args) { int[] p = new int[] {55, 66, 88, 99, 111, 122, 133}; int j; Console.WriteLine("Initial Array......"); for (j = 0; j < p.Length; j++ ) { Console.WriteLine("arr[j] = {0}", p[j]); } // set new element at index 2 p[2] = 77; Console.WriteLine("New Array......"); for (j = 0; j < p.Length; j++ ) { Console.WriteLine("arr[j] = {0}", p[j]); } } } }
Output
Initial Array...... arr[j] = 55 arr[j] = 66 arr[j] = 88 arr[j] = 99 arr[j] = 111 arr[j] = 122 arr[j] = 133 New Array...... arr[j] = 55 arr[j] = 66 arr[j] = 77 arr[j] = 99 arr[j] = 111 arr[j] = 122 arr[j] = 133
- Related Articles
- Set the bit at a specific position in the BitArray to the specified value in C#?
- Insert the specified element at the specified position in Java CopyOnWriteArrayList
- How to copy the entire ArrayList to a one-dimensional Array in C# ?
- Get or set the element at the specified index in ArrayList in C#
- Get or set the element at specified index in Collection in C#
- Copying the Queue elements to one-dimensional array in C#
- Set all bits in the BitArray to the specified value in C#
- Copy StringDictionary to Array at the specified index in C#
- How to move an array element from one array position to another in Java?
- Copy ListDictionary to Array instance at the specified index in C#
- Insert a specified element in a specified position in JavaScript?
- Compute the bit-wise AND of a One Dimensional and a zero-dimensional array element-wise in Numpy
- Adding an element at a given position of the array in Javascript
- Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy
- Remove the element at the specified index of the ArrayList in C#

Advertisements