Keep In mind I don’t have much coding experience…
I’m having problem’s accessing an Array.
I’m creating the Array using a function that returns a Array here’s an example:
int[] ArrayName = ReturnArray(string);
So now that ArrayName has been created it should be identical to what ReturnArray returned should it not?
Well I set a breakpoint right on :
int[] ArrayName = ReturnArray(string);
I can see that ArrayName was created properly.
Well when I try to access just 1 value of the Array like so:
print(ArrayName[0]);
It should only return the first value in the array right? well It’s not!
It returns a MORE THAN ONE VALUE and the value’s Don’t even match what ReturnArray(string) Returned
Here is the “ReturnArray” function :
public static int[] ReturnArray(string t)
{
int i,ii,;
string ba;
string base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
List<int> list = new List<int>();
for (i = 0; i < t.Length;i++)
{
ba = t.Substring(i, 1);
ii = base64.IndexOf(ba) * 64;
list.Add(ii);
}
return list.ToArray();
}
Added more code do to response’s from comments
private void outputLoop()
{
int i = 0;
for (i = 0; i < 63; i++)
{
int te = lines[i].Length - 128;
string tes = lines[i].Substring(te, 64);
int[] ArrayName = ReturnArray(tes);
_textlayer.DrawString(_font, ArrayName[i].ToString(), new Vector2(1100, i * 15), Color.White);
}
}
Here’s a working sample. Let’s deconstruct.
First, if you are trying to make a base 64 algorithm, it’s already been done and in the framework. If you are trying to learn, that’s great, but there are examples out there to go on.
Secondly, your code does return what I would expect, i.e. an array of numbers which come from the product of
IndexOf() * 64.This little example yields
1984, 2560, 2560for “foo” and the value at index 0 is 1984.“AAA” yields
0, 0, 0, because IndexOf() is 0 * 64.As you would expect, “BBB” yields
64, 64, 64, because IndexOf() returns 1, and it is multiplied by 64.More debugging code (based on comments):