DEV Community

Cover image for CRUD operations on Arrays
LetsUpdateSkills
LetsUpdateSkills

Posted on

CRUD operations on Arrays

Arrays in C# are fixed in size and do not have built-in methods for dynamic operations (like Add or Remove). However, you can perform CRUD operations by working with array elements.

1. Create Operation

You can initialize arrays with specific values or create an empty array and populate it later.

Example

// Creating an array with predefined values
int[] numbers = { 10, 20, 30 };

// Creating an empty array and assigning values later
int[] grades = new int[3];
grades[0] = 85;
grades[1] = 90;
grades[2] = 78;

Enter fullscreen mode Exit fullscreen mode

2. Read Operation

Access specific elements or iterate through the array.

Example

int[] numbers = { 10, 20, 30 };

// Accessing elements by index
Console.WriteLine(numbers[0]); // Output: 10

// Iterating through the array
foreach (var num in numbers)
{
    Console.WriteLine(num);
}

Enter fullscreen mode Exit fullscreen mode

3. Update Operation

Modify existing elements by accessing them via their index.

int[] numbers = { 10, 20, 30 };

// Updating the value at index 1
numbers[1] = 25;

foreach (var num in numbers)
{
    Console.WriteLine(num);
}
// Output: 10, 25, 30

Enter fullscreen mode Exit fullscreen mode

Please click here to see complete tutorial

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry đź‘€

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay