I need help writing my method that accepts a single parameter long i
:
public static string GetWord(long i)
{
string s = "";
//Update s using i
return s;
}
...for my program that saves a file of ASCII words...
public static void main(string[] args)
{
try
{
int First = int.Parse(args[0]);
int Last = int.Parse(args[1])
string Filename = args[2]
for(int i = start; i <= end; i++)
File.AppendLine(Filename, GetWord(i));
Console.WriteLine("Process complete");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
...with the following pattern.
GetWord(0)
should be the result of Encoding.ASCII.GetString(new byte[]{ 0 });
GetWord(1)
should be the result of Encoding.ASCII.GetString(new byte[]{ 1 });
GetWord(2)
should be the result of Encoding.ASCII.GetString(new byte[]{ 2 });
...and so on until GetWord(127)
.
GetWord(128)
should be the result of GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 0 });
GetWord(129)
should be the result of GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 1 });
GetWord(130)
should be the result of GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 2 });
...and so on until GetWord(255)
.
GetWord(256)
should be the result of GetWord(1) + Encoding.ASCII.GetString(new byte[]{ 0 });
GetWord(257)
should be the result of GetWord(1) + Encoding.ASCII.GetString(new byte[]{ 1 });
GetWord(258)
should be the result of GetWord(1) + Encoding.ASCII.GetString(new byte[]{ 2 });
...and so on until GetWord(16383)
.
GetWord(16384)
should be the result of GetWord(0) + GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 0 });
GetWord(16385)
should be the result of GetWord(0) + GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 1 });
GetWord(16386)
should be the result of GetWord(0) + GetWord(0) + Encoding.ASCII.GetString(new byte[]{ 2 });
Writing the pattern down helps me think about the code. I hope this makes sense to everyone. I think I need to use a mixture of recursion and modulus to get this to work.