I keep getting this same error message,
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index" when I try to populate an arraylist from a char.
What i want to do is just to switch place of chars in octets f.ex. 21 43 65 87 should becomme 12345678
and if the octets are like 21 43 65 F7 it should becomme 1234567
here is my code:
public string SemiOctetDecode(string rawOctet, bool isDecimal)
// Decodes decimal and none decimal semi octets
ArrayList decodedOctet = new ArrayList(rawOctet.Length);
if (isDecimal = true && rawOctet[(rawOctet.Length - 2)] == 'F')
decodedOctet.Capacity = (rawOctet.Length - 1);
// Switches places of the two numbers in the octet.
for(int i = 0; i < (decodedOctet.Capacity); i++)
if (i % 2 == 0)
// Takes second char of each octet and put it in first place in corresponding temp "octet"
decodedOctet[i] = rawOctet[(i + 1)];
// Takes first char of each octet and put it in second place in corresponding temp "octet"
decodedOctet[i] = rawOctet[(i - 1)];