I've tried to save args[0]
into string lemon
, but whatever I tried it didn't work at all, it instead threw an IndexOutOfRange
exception:
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at NHBloater.Program.Main(String[] args) in C:\Users...\Program.cs:line 12
I tried:
catch
ing it- adding
if (args.Length > 0)
- searching on Google and Stack Overflow
Edit: I fixed it but don't know how, and the code that's worrying me is output += inputArray[i]
Here is the code with the first line being line 10 without the attempts to fix it: c#:
static void Main(string[] args)
{
string lemon = args[0];
string input = File.ReadAllText(lemon);
string[] inputArray = input.Split();
string output = "";
for (int i = 0; i < input.Length; i++)
for (int j = 0; j < Convert.ToInt32(args[2]); j++)
output += inputArray[i];
File.WriteAllText(args[1], output);
}
Imported libraries:
System
System.IO
System.Text
Arguments:
"h.txt"
"h2.txt"
"5"