Hello, I have a problem with the args-array. when I compile the code below - I get the error: index was out of array range, so what am I doing wrong? Thank you.
code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int i;
- args[0] = "Jurgen01";
- args[1] = "Jurgen02";
- //pruefen ob beimProgrammaufruf eine oder mehrere
- //Zeichenfolgen uebergebenworden sind
- //array args der methode main
- //error - index was out of array range
- if (args.Length > 0)
- {
- //die Zeichenfolge an der Konsole anzeigen
- for (i = 0; i < args.Length; i++)
- Console.WriteLine(args[i]);
- }
- else
- {
- Console.WriteLine("Kein Uebergabestring");
- }
- Console.ReadLine();
- }
- }
- }
Jared GaynorPosted May 10, 2019, 12:55 PM
Tilo JungPosted May 10, 2019, 1:12 PM