
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 add items/elements to an existing jagged array in C#?
To add an element to existing jagged array, just set the value of the element with a new value.
Let’s say you need to add an element at the following location −
a[3][1]
Just set the value −
a[3][1] = 500;
Above, we accessed the first element of the 3rd array in a jagged array.
Let us see the complete code −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int[][] x = new int[][]{new int[]{10,20},new int[]{30,40}, new int[]{50,60},new int[]{ 70, 80 }, new int[]{ 90, 100 } }; int i, j; Console.WriteLine("Old Array..."); for (i = 0; i < 5; i++) { for (j = 0; j < 2; j++) { Console.WriteLine("a[{0}][{1}] = {2}", i, j, x[i][j]); } } x[3][1] = 500; Console.WriteLine("New Array..."); for (i = 0; i < 5; i++) { for (j = 0; j < 2; j++) { Console.WriteLine("a[{0}][{1}] = {2}", i, j, x[i][j]); } } Console.ReadKey(); } } }
- Related Questions & Answers
- How to access elements from jagged array in C#?
- How to add items to an array in java dynamically?
- How to add new value to an existing array in JavaScript?
- How to use use an array of pointers (Jagged) in C/C++?
- How do I push elements to an existing array in MongoDB?
- Jagged Array in C#
- How to add columns to an existing MySQL table?
- How to add column to an existing table in PostgreSQL?
- Add alpha to an existing Matplotlib colormap
- C program to add all perfect square elements in an array.
- How to add current date to an existing MySQL table?
- How to add items to a list in C#?
- How to add elements to the midpoint of an array in Java?
- How to add/append content to an existing file using Java?
- How to add a title to an existing line border in Java?
Advertisements