Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sicherheitslücken (CVE)USN-8797-1: GStreamer Base Plugins vulnerability(21.09.2026 um 20:05 Uhr)
Sichere ProgrammierungYou can build HTML emails with Tailwind CSS(21.09.2026 um 22:15 Uhr)
Sichere ProgrammierungDEV-Part-1-Backend.md(21.09.2026 um 22:24 Uhr)
Sichere ProgrammierungWhat It Actually Costs to Serve a 1M-Token Model in Production(21.09.2026 um 22:33 Uhr)
Sichere ProgrammierungHow to Check an Agent's Diagnosis Before It Touches Production(21.09.2026 um 22:53 Uhr)
Linux Tipps & HardeningWhat if Spotify was self-hosted? I think I got pretty close.(21.09.2026 um 22:33 Uhr)
Linux Tipps & HardeningSandboxing on Linux(21.09.2026 um 22:45 Uhr)
Sicherheitslücken (CVE)USN-8797-1: GStreamer Base Plugins vulnerability(21.09.2026 um 20:05 Uhr)
Sichere ProgrammierungYou can build HTML emails with Tailwind CSS(21.09.2026 um 22:15 Uhr)
Sichere ProgrammierungDEV-Part-1-Backend.md(21.09.2026 um 22:24 Uhr)
Sichere ProgrammierungWhat It Actually Costs to Serve a 1M-Token Model in Production(21.09.2026 um 22:33 Uhr)
Sichere ProgrammierungHow to Check an Agent's Diagnosis Before It Touches Production(21.09.2026 um 22:53 Uhr)
Linux Tipps & HardeningWhat if Spotify was self-hosted? I think I got pretty close.(21.09.2026 um 22:33 Uhr)
Linux Tipps & HardeningSandboxing on Linux(21.09.2026 um 22:45 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

27. C# (Arrays)

Full Runnable Code using System; class Program { static void Main() { // 1) Declare + allocate (check default values) int[] numbers = new int[3]; Console.WriteLine("Default values:"); …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Full Runnable Code






using System;

class Program
{
static void Main()
{
// 1) Declare + allocate (check default values)
int[] numbers = new int[3];

Console.WriteLine("Default values:");
Console.WriteLine(numbers[0]);
Console.WriteLine(numbers[1]);
Console.WriteLine(numbers[2]);
Console.WriteLine();

// 2) Update values
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;

Console.WriteLine("After updates:");
for (int i = 0; i < numbers.Length; i++)
{
Console.WriteLine(numbers[i]);
}
Console.WriteLine();

// 3) Index from End (^)
int[] numbers2 = { 10, 20, 30, 40, 50 };

Console.WriteLine("Access from the end:");
Console.WriteLine(numbers2[^1]); // 50
Console.WriteLine(numbers2[^2]); // 40
Console.WriteLine();

// 4) Sum all values
int sum = 0;

for (int i = 0; i < numbers2.Length; i++)
{
sum += numbers2[i];
}

Console.WriteLine("Sum:");
Console.WriteLine(sum);

Console.ReadKey();
}
}












0. The Real Goal of This Lesson




An array is not “multiple variables.”

It is one structure that stores many values of the same type under a single reference.




If you miss this:




  • Index logic feels random

  • Off-by-one bugs keep happening

  • Runtime errors feel “mysterious”



This lesson is about understanding the execution model.









1. What Is an Array?



A variable is one box:




int number = 10;






An array is multiple boxes as one structure:




int[] numbers = new int[3];






Meaning:




  • Allocate space for 3 int values

  • Each element is filled with the default value (0)









2. Index Starts at 0



If the array size is 3:




index: 0 1 2






The last valid index is always:




Length - 1






This is non-negotiable.









3. Compile-Time Error vs Runtime Error






Compile-Time Error (Type Mismatch)






numbers[0] = "hello"; // invalid type






The compiler blocks execution.



The program cannot run.









Runtime Error (Index Out of Range)






numbers[3] = 100; // index out of range






Compilation succeeds.



The program starts.



Then it crashes during execution.



Typical error:




Index was outside the bounds of the array






This is the exact difference:




  • Type mistakes fail early (compile-time)

  • Index mistakes fail late (runtime)









4. The Most Common Beginner Mistake






numbers[numbers.Length]






If Length = 3, valid indices are:



0, 1, 2



So numbers[3] is invalid.



Rule:




Last index = Length - 1










5. The ^ Operator (Index from End)






numbers2[^1]






Meaning:




  • Last element



Equivalent to:




numbers2[numbers2.Length - 1]






So:





  • ^1 → last


  • ^2 → second last



It is a convenience feature.



The indexing rules are still the same.









6. The One Rule You Must Not Break in for Loops



Correct:




i < numbers.Length






Incorrect:




i <= numbers.Length






Why?



Because the final iteration will produce:




i == Length






And numbers[Length] is out of range.



This is the classic off-by-one error.









7. The Biggest Limitation of Arrays




Arrays have fixed size.





new int[3]






Those 3 slots stay 3 slots.



You cannot grow or shrink the array.



So:




  • Fixed count → array

  • Variable count → later use List<T>









Final Summary




An array is an index-based structure that stores a fixed number of same-type values.










Learning Check (One Question)



Explain exactly when the runtime error occurs, step by step, tracking i:




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

for (int i = 0; i <= numbers.Length; i++)
{
Console.WriteLine(numbers[i]);
}






You must answer:




  • How does i change starting from 0?

  • What is numbers.Length here?

  • What is the final value of i?

  • At which exact moment does the crash happen, and why?

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 27. C# (Arrays)

Thematisch verwandte Begriffe: Arrays · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-45381 | Tautulli is a Python based monitoring and tracking tool for Plex Media S…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick