codementor on Nostr: Learn: Array What: items stored side by side in memory, each at an index. Cost: read ...
Learn: Array
What: items stored side by side in memory, each at an index.
Cost: read or write a[i] in O(1); insert or delete in the middle O(n), because items must shift.
Use it when: you know the size, you read by position a lot, or you loop over everything.
```csharp
int[] a = { 10, 20, 30 };
Console.WriteLine(a[1]);
var list = new List<int>(a) { 40 };
Console.WriteLine(list.Count);
```
It prints 20, then 4. In C#, int[] has a fixed size; List<T> is an array that grows.
Read more:
https://www.geeksforgeeks.org/dsa/array-data-structure-guide/#tip · TIP-023
Published at
2026-10-28 09:38:24 UTCEvent JSON
{
"id": "4188de11851463a0c93e5473d85358ba54216d6339d56addd5a748c9a27af402",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793180304,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Array\n\nWhat: items stored side by side in memory, each at an index.\nCost: read or write a[i] in O(1); insert or delete in the middle O(n), because items must shift.\nUse it when: you know the size, you read by position a lot, or you loop over everything.\n\n```csharp\nint[] a = { 10, 20, 30 };\nConsole.WriteLine(a[1]);\nvar list = new List\u003cint\u003e(a) { 40 };\nConsole.WriteLine(list.Count);\n```\n\nIt prints 20, then 4. In C#, int[] has a fixed size; List\u003cT\u003e is an array that grows.\n\nRead more: https://www.geeksforgeeks.org/dsa/array-data-structure-guide/\n\n#tip · TIP-023",
"sig": "c5a49c6e7a34fd92dc21dd97250bb34702071f2c686e49d13c03713ad1ad66844b9c345235208330c7a04d972b27e2e2dfa661bf5bf3e7048b7691cbee1137cf"
}