
- 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 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 Articles
- How to access elements from jagged array in C#?
- How to add new value to an existing array in JavaScript?
- How to add items to an array in java dynamically?
- How to use use an array of pointers (Jagged) in C/C++?
- How do I push elements to an existing array in MongoDB?
- How to add elements to an Array using filters in Vue ?
- Jagged Array in C#
- How to add column to an existing table in PostgreSQL?
- C program to add all perfect square elements in an array.
- How to add columns to an existing MySQL table?
- How to add elements to the midpoint of an array in Java?
- How to add items to a list in C#?
- How to Add Items to Hashtable Collection in C#
- How to add current date to an existing MySQL table?
- How to add new array elements at the beginning of an array in JavaScript?

Advertisements