> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/datatypes/composite-datatypes/arrays.md).

# Arrays

Arrays in computer programming are a fundamental data structure used to store collections of elements. Each element in an array is identified by at least one array index or key. An array can store data of a specific type, be it integer, string, or any other data types. The key feature of an array is that it allows random access of elements. This means that one can access any element in the array directly if the index of the element is known.

Arrays are useful in situations where there is a need to store a list of values of the same type. They are often used to store data like lists of usernames, scores in a game, or inventory items in an application.

#### Example in Python

In Python, arrays can be created by using the `list` data type, which is more flexible and can contain elements of different data types.

```python
# Creating an array in Python
numbers = [1, 2, 3, 4, 5]  # This is a list, commonly used as an array in Python
print(numbers[2])  # Accessing the third element (index starts at 0), which will print 3
```

#### Example in C\#

In C#, arrays are strongly typed, meaning they can only contain elements of the same data type. They are defined with a specific data type, and their size must be specified at the time of declaration (or initialized directly).

```csharp
// Creating an array in C#
int[] numbers = new int[5] {1, 2, 3, 4, 5};  // Declaration and initialization of an array
Console.WriteLine(numbers[2]);  // Accessing the third element, which will print 3
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/datatypes/composite-datatypes/arrays.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
